tensorflow / tensorflow/models

Cannot convert ssd OD models into tflite

Open
#9,537 3 comments 0 reactions 3 assignees View on GitHub

@pkulzc is already working on this.

Since Dec 8, 2020.

models:research:odapi type:bug
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

The pre-trained model I used: ssd_mobilenet_v1_fpn_640x640_coco17_tpu-8.
The code I used is below:

converter = tf.lite.TFLiteConverter.from_saved_model(model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model_quant = converter.convert()
interpreter = tf.lite.Interpreter(model_content=tflite_model_quant)

When I try on the saved model generated through object_detection/export_tflite_graph_tf2.py as described here, I got the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-ed31809d0211> in <module>
     15 tflite_model_quant = converter.convert()
     16 
---> 17 interpreter = tf.lite.Interpreter(model_content=tflite_model_quant)
     18 input_type = interpreter.get_input_details()[0]['dtype']
     19 print('input: ', input_type)

~/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/interpreter.py in __init__(self, model_path, model_content, experimental_delegates, num_threads)
    206       self._interpreter = (
    207           _interpreter_wrapper.CreateWrapperFromBuffer(
--> 208               model_content, self._custom_op_registerers))
    209     elif not model_content and not model_path:
    210       raise ValueError('`model_path` or `model_content` must be specified.')

ValueError: Did not get operators or tensors in subgraph 0.

I also tried the saved_model coming with the original pre-trained checkpoint coming from the model zoo, I got another error:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/convert.py in toco_convert_protos(model_flags_str, toco_flags_str, input_data_str, debug_info_str, enable_mlir_converter)
    198                                                  debug_info_str,
--> 199                                                  enable_mlir_converter)
    200       return model_str

~/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/wrap_toco.py in wrapped_toco_convert(model_flags_str, toco_flags_str, input_data_str, debug_info_str, enable_mlir_converter)
     37       debug_info_str,
---> 38       enable_mlir_converter)
     39 

Exception: <unknown>:0: error: loc("Func/StatefulPartitionedCall/input/_0"): requires all operands and results to have compatible element types
<unknown>:0: note: loc("Func/StatefulPartitionedCall/input/_0"): see current operation: %1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x?x?x3x!tf.quint8>) -> tensor<1x?x?x3xui8>

My ultimate goal is to test the accuracy of OD models after quantization. Now I cannot even convert model, let alone quantization. Can anyone help me on this?

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04):
  • TensorFlow installed from (binary through pip):
  • TensorFlow version (2.3.1):
  • Python version: 3.7.6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.