首页 > 解决方案 > 通过量化将 Mobilenet SSD 转换为 TensorFlow Lite

问题描述

我的目标很简单,我想。我想将预训练的 mobilenetv2(或 v1)ssd 模型转换为 TFLite,并按照此处所述进行量化和优化。但即使没有任何量化,将模型转换为 TFLite 模型时也会出错。

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() 

错误信息:

\tensorflow/lite/toco/toco_tooling.h:38] 检查失败:s.ok() 发现 StridedSlice 作为 Switch 的非选定输出,但仅支持 Merge。一般不支持 Switch 和 Merge 等控制流操作。我们正在努力解决这个问题,请参阅 Github 问题https://github.com/tensorflow/tensorflow/issues/28485。致命的 Python 错误:中止

我花了几天时间将预训练的 mobilenetv2 ssd 模型转换为 TFLite。我知道命令行 (export_tflite_ssd_graph.py) 解决方案适用于转换,但不适用于限定部分。我也想编写 python 代码来做同样的事情并优化(压缩、量化)模型。我一直没能做到。有什么建议么?

我的问题可以总结如下:

  1. 如何使用类似于上述代码块的 python 代码将预训练的 mobilenetv2(或 v1)ssd 模型转换为具有量化和优化的 TFLite。
  2. 如何将预训练的 mobilenetv2(或 v1)ssd 模型转换为 TFLite,并使用命令行进行量化和优化(对象检测 API 和 TFLite API,如果有)

标签: tensorflowobject-detectiontensorflow-liteobject-detection-apimobilenet

解决方案


似乎此模型中有不受支持的操作。

您可以在这里找到预训练的“COCO SSD MobileNet v1”tflite 模型


推荐阅读