0
votes

My goal is simple, I think. I want to convert a pre-trained mobilenetv2 (or v1) ssd model to TFLite with quantization and optimization as described HERE. But even without any quantization, I am getting errors converting the model to TFLite model.

model = tf.saved_model.load(detection_model_dir)
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 = tf.compat.v1.lite.TFLiteConverter.from_saved_model(detection_model_dir, input_shapes={"image_tensor" : [1,300,300,3]})
tflite_model = converter.convert() 

Error Messages:

2020-04-29 13:23:58.432192: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayWriteV3 2020-04-29 13:23:58.432342: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayWriteV3 2020-04-29 13:23:58.782402: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 4058 operators, 6882 arrays (0 quantized) 2020-04-29 13:23:59.302999: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 4005 operators, 6778 arrays (0 quantized) 2020-04-29 13:23:59.925648: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 4005 operators, 6778 arrays (0 quantized) 2020-04-29 13:24:00.227644: F .\tensorflow/lite/toco/toco_tooling.h:38] Check failed: s.ok() Found StridedSlice as non-selected output from Switch, but only Merge supported. Control flow ops like Switch and Merge are not generally supported. We are working on fixing this, please see the Github issue at https://github.com/tensorflow/tensorflow/issues/28485. Fatal Python error: Aborted

I have spent days on converting a pretrained mobilenetv2 ssd model to TFLite. I know the command line (export_tflite_ssd_graph.py) solution works for the conversion but not the qualization part. I also would like to write python code to do the same thing and optimize (compress, quantize) the model. I have been failing in doing it. Any suggestions?

My questions can be summarized as below:

  1. How to convert a pre-trained mobilenetv2 (or v1) ssd model to TFLite with quantization and optimization using python code similar to the above code block.
  2. How to convert a pre-trained mobilenetv2 (or v1) ssd model to TFLite with quantization and optimization with command lines (object detection API and TFLite APIs if any)
1
Have you used the quantized versions of the models? I use these commands in Google Colab notebook to get the quantized TFLite models: gist.github.com/drajsel/0961486c49e8058acb216aaea76d4685Waddles
That is a good suggestion. Thanks a lot! I am still looking to have a solution with a few lines of code.jackyvr

1 Answers

0
votes

Seems there're unsupported ops in this model.

You could found pre-trained "COCO SSD MobileNet v1" tflite model here