ValueError: None is only supported in the 1st dimension. Tensor ‘image_tensor’ has invalid shape ‘[None, None, None, 3]’

I am using faster_rcnn_inception_v2_coco model and want to convert it into tflite…
import tensorflow as tf

tflite_model_name=”TF.lite”

saved_model_dir=”exported_output_graph/saved_model/saved_model.pb”
#Convert the model
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) # path to the SavedModel directory
tflite_model = converter.convert()
with open(tflite_model_name, ‘wb’) as f:
f.write(tflite_model)
I don’t what I am missing here

1. System information

  • OS Platform and Distribution =Linux
  • TensorFlow library =1.14

1 possible answer(s) on “ValueError: None is only supported in the 1st dimension. Tensor ‘image_tensor’ has invalid shape ‘[None, None, None, 3]’

  1. I could the input and output tensor names from https://github.com/openvinotoolkit/open_model_zoo/blob/master/models/public/faster_rcnn_inception_v2_coco/faster_rcnn_inception_v2_coco.md.

    I could successfully convert the above frozen graph def by using the following code snippet.

      converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph("/tmp/fg.pb", ["image_tensor"], ["detection_classes", "detection_scores", "detection_boxes", "num_detections"])
      converter.target_spec.supported_ops = [
        tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS
      ]
      model = converter.convert()
    

ValueError: None is only supported in the 1st dimension. Tensor ‘image_tensor’ has invalid shape ‘[None, None, None, 3]’.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Linux Ubuntu 18.04
  • TensorFlow installed from (source or binary): pip install
  • TensorFlow version (or github SHA if from source): 2.1.0

Command used to run the converter or code if you’re using the Python API
If possible, please share a link to Colab/Jupyter/any notebook.

tflite_convert --saved_model_dir=/path/to/automl/efficientdet/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/saved_model/ --output_file=/path/to/automl/efficientdet/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/

The output from the converter invocation

Traceback (most recent call last):

  File "/home/hulining/.local/bin/tflite_convert", line 11, in <module>
    sys.exit(main())

  File "/home/hulining/.local/lib/python3.6/site-packages/tensorflow/lite/python/tflite_convert.py", line 503, in main

    app.run(main=run_main, argv=sys.argv[:1])

  File "/home/hulining/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run

    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)

  File "/home/hulining/.local/lib/python3.6/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)

  File "/home/hulining/.local/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))

  File "/home/hulining/.local/lib/python3.6/site-packages/tensorflow/lite/python/tflite_convert.py", line 499, in run_main

    _convert_tf1_model(tflite_flags)

  File "/home/hulining/.local/lib/python3.6/site-packages/tensorflow/lite/python/tflite_convert.py", line 193, in _convert_tf1_model

    output_data = converter.convert()

  File "/home/hulining/.local/lib/python3.6/site-packages/tensorflow/lite/python/lite.py", line 811, in convert

    _get_tensor_name(tensor), shape_list))

ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'.

Also, please include a link to the saved model or GraphDef

https://github.com/google/automl/tree/master/efficientdet

http://download.tensorflow.org/models/object_detection/ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz

http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz

Failure details
I tried several ways like Python API and command line and several models above to convert a .pb file to a tflite file. Both of them failed with the error above.
don’t know how to slove the error.

1 possible answer(s) on “ValueError: None is only supported in the 1st dimension. Tensor ‘image_tensor’ has invalid shape ‘[None, None, None, 3]’.

  1. Of course. @jvishnuvardhan
    with the command line mode, I used:

     tflite_convert --saved_model_dir=/path/to/automl/efficientdet/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/saved_model/ --output_file=/path/to/automl/efficientdet/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/
    

    with the python API code, the code is:

    converter = tf.lite.TFLiteConverter.from_saved_model('saved_model',signature_keys=['serving_default'])
    
    converter.optimizations = [tf.lite.Optimize.DEFAULT]
    converter.experimental_new_converter = True
    converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
    
    tflite_model = converter.convert()
    
    open("saved_model/converted_model.tflite", "wb").write(tflite_model)
    

    The transfered model may not be same (all from the link I shared above), but the error is the same.

    BTW, my GPU is RTX 2080 Ti as another reference, don’t know if it will affect.