Hi community,
I have an issue with tf1 object detection models at model zoo. Especially I want to convert faster_rcnn_inception_v2_coco. Inside the folder if you download it there is a saved_model and a frozen_inference_graph.pb
- With the saved model I use a concrete function to convert it:
model = tf.saved_model.load('/content/faster_rcnn_inception_v2_coco_2018_01_28/saved_model')
concrete_func = model.signatures[
tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
concrete_func.inputs[0].set_shape([1, 300, 300, 3])
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()
with open('detect2.tflite', 'wb') as f:
f.write(tflite_model)
the .tflite file is generated without errors but it seems that it throws an error inside android:
java.lang.RuntimeException: java.lang.IllegalArgumentException: Internal error: Cannot create interpreter: Did not get operators or tensors in subgraph 1.
- With the frozen graph the conversion procedure fails:
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
graph_def_file = '/content/faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb',
input_arrays = ['image_tensor'],
output_arrays = ['detection_boxes', 'detection_classes', 'detection_scores', 'num_detections']
)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()
with open('detect.tflite', 'wb') as f:
f.write(tflite_model)
ConverterError: Merge of two inputs that differ on more than one predicate {s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/Greater:0,else), s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/cond/cond/pred_id/_390__cf__396:0,then), s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/cond/Greater/_389__cf__395:0,then)} and {s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/Greater:0,else), s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/cond/cond/pred_id/_390__cf__396:0,else), s(SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/cond/Greater/_389__cf__395:0,else)} for node {{node SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/PadOrClipBoxList/cond/cond/Merge}} Failed to functionalize Control Flow V1 ops. Consider using Control Flow V2 ops instead.
I use colab and TensorFlow version is 2.7.0
Does anyone know how to overcome the above error or a different procedure for successful conversion of the tf1 files of model zoo?
Thanks in advance.