Description
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04 x86_64): Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64
- TensorFlow installed from (source or binary): binary Java-bindings and native libraries with Maven-dependency
- TensorFlow version (use command below): org.tensorflow.tensorflow-core-platform:1.0.0, org.tensorflow.tensorflow-core-native-macosx-arm64:1.0.0
- Java version (i.e., the output of
java -version
): openjdk version "21.0.7" 2025-04-15 - Java command line flags (e.g., GC parameters): -
- Python version (if transferring a model trained in Python): -
- Bazel version (if compiling from source): -
- GCC/Compiler version (if compiling from source): -
- CUDA/cuDNN version: used with CPU
- GPU model and memory: used with CPU
Describe the current behavior
I am trying to load pre-trained model faster_rcnn/inception_resnet_v2 with help of Java-bindings and native libraries. After exploring downloaded model with the command:
saved_model_cli show --dir /fasterrcnn --all
I have got next information:
MetaGraphDef with tag-set: '' contains the following SignatureDefs:
signature_def['default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['images'] tensor_info:
dtype: DT_FLOAT
shape: (1, -1, -1, 3)
name: hub_input/image_tensor:0
The given SavedModel SignatureDef contains the following output(s):
outputs['detection_boxes'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 4)
name: hub_input/strided_slice:0
outputs['detection_class_entities'] tensor_info:
dtype: DT_STRING
shape: (-1, 1)
name: hub_input/index_to_string_Lookup:0
outputs['detection_class_labels'] tensor_info:
dtype: DT_INT64
shape: (-1, 1)
name: hub_input/strided_slice_2:0
outputs['detection_class_names'] tensor_info:
dtype: DT_STRING
shape: (-1, 1)
name: hub_input/index_to_string_1_Lookup:0
outputs['detection_scores'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 1)
name: hub_input/strided_slice_1:0
Method name is:
The MetaGraph with tag set [] contains the following ops: {'Where', 'GatherV2', 'Softmax', 'Transpose', 'Range', 'ResizeBilinear', 'Exp', 'Shape', 'AvgPool', 'Sqrt', 'Mean', 'Switch', 'Merge', 'Maximum', 'Sub', 'Equal', 'Exit', 'BiasAdd', 'RealDiv', 'SpaceToBatchND', 'Max', 'Squeeze', 'FusedBatchNorm', 'Slice', 'NonMaxSuppressionV3', 'TensorArrayScatterV3', 'MatMul', 'StridedSlice', 'HashTableV2', 'Split', 'Unpack', 'Size', 'Pack', 'InitializeTableV2', 'Identity', 'TensorArrayWriteV3', 'Assert', 'Less', 'Greater', 'Relu', 'Minimum', 'Fill', 'LogicalAnd', 'TopKV2', 'Mul', 'LoopCond', 'TensorArrayReadV3', 'CropAndResize', 'Relu6', 'Add', 'Round', 'TensorArrayV3', 'Enter', 'All', 'Cast', 'ExpandDims', 'Reshape', 'NextIteration', 'ConcatV2', 'Tile', 'Rank', 'TensorArraySizeV3', 'LookupTableFindV2', 'Conv2D', 'ZerosLike', 'TensorArrayGatherV3', 'MaxPool', 'FloorMod', 'Placeholder', 'Const', 'BatchToSpaceND'}
As you can see, this model provides an empty set of tags. After trying to load this model with next code:
SavedModelBundle.load("/fasterrcnn");
or with code:
SavedModelBundle.load("/fasterrcnn",new String[]{});
I have got next error:
Caused by: org.tensorflow.exceptions.TensorFlowException: Could not find meta graph def matching supplied tags: { serve }. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:90)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:590)
at org.tensorflow.SavedModelBundle$Loader.load(SavedModelBundle.java:92)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:335)
at org.antools.aiserver4j.core.model.impl.tensorflow.TensorFlowModel.<init>(TensorFlowModel.java:52)
... 230 common frames omitted
After some investigation I have understood, that serve tag is used as default value (see static value org.tensorflow.SavedModelBundle.DEFAULT_TAG) for the field org.tensorflow.SavedModelBundle.tags. The problem is, that it is used both for the case, when no tags are provided (like: SavedModelBundle.load("/fasterrcnn") and for the case, when empty set of tags is provided (like: SavedModelBundle.load("/fasterrcnn",new String[]{}), because of the code snippet in the class org.tensorflow.SavedModelBundle (as field org.tensorflow.SavedModelBundle.tags is left with null value, so default value org.tensorflow.SavedModelBundle.DEFAULT_TAG is used)
public static SavedModelBundle load(String exportDir, String... tags) {
Loader loader = loader(exportDir);
if (tags != null && tags.length > 0) {
loader.withTags(tags);
}
return loader.load();
}
Describe the expected behavior
Expected behavior is that in the case of explicit empty list of tags sending (like: SavedModelBundle.load("/fasterrcnn",new String[]{}), empty list of tags is passed unchanged to the native library code, and no default tag value is used.
Code to reproduce the issue
Test case to reproduce the problem is described above.