【问题标题】:Convert Mobilenet SSD to TensorFlow Lite with quantization通过量化将 Mobilenet SSD 转换为 TensorFlow Lite
【发布时间】:2020-04-29 20:44:50
【问题描述】:

我想我的目标很简单。我想将预训练的 mobilenetv2(或 v1)ssd 模型转换为具有量化和优化的 TFLite,如 HERE 所述。但即使没有任何量化,将模型转换为 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() 

错误信息:

2020-04-29 13:23:58.432192:I tensorflow/lite/toco/import_tensorflow.cc:659] 转换不支持的操作:TensorArrayWriteV3 2020-04-29 13:23:58.432342:I tensorflow/lite/toco/import_tensorflow.cc:659] 转换不支持的操作:TensorArrayWriteV3 2020-04-29 13:23:58.782402: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] 在删除未使用的操作之前:4058 个运算符,6882 个数组(0 量化) 2020-04-29 13:23:59.302999:我 tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] 删除未使用的操作后通过 1:4005 个运算符,6778 个数组(0 量化) 2020-04-29 13:23:59.925648: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] 在一般图形转换之前:4005 个运算符,6778 个数组(0 量化) 2020-04-29 13:24:00.227644: F .\tensorflow/lite/toco/toco_tooling.h:38] 检查失败:s.ok() 发现 StridedSlice 作为 Switch 的非选定输出,但仅支持 Merge。一般不支持 Switch 和 Merge 等控制流操作。我们正在努力解决这个问题,请参阅https://github.com/tensorflow/tensorflow/issues/28485 的 Github 问题。 致命的 Python 错误:已中止

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

我的问题可以总结如下:

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

【问题讨论】:

标签: tensorflow object-detection tensorflow-lite object-detection-api mobilenet


【解决方案1】:

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

你可以找到预训练的“COCO SSD MobileNet v1”tflite模型here

【讨论】:

  • 谢谢。我仍然希望用我自己的数据集来构建模型。
  • 在哪里可以找到相同型号的 em v2 版本?我需要更多的准确性
猜你喜欢
  • 1970-01-01
  • 2018-11-07
  • 2018-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-07
  • 2021-02-11
  • 2020-12-03
相关资源
最近更新 更多