tensorflow - 通过量化将 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 代码来做同样的事情并优化(压缩、量化)模型。我一直没能做到。有什么建议么?
我的问题可以总结如下:
- 如何使用类似于上述代码块的 python 代码将预训练的 mobilenetv2(或 v1)ssd 模型转换为具有量化和优化的 TFLite。
- 如何将预训练的 mobilenetv2(或 v1)ssd 模型转换为 TFLite,并使用命令行进行量化和优化(对象检测 API 和 TFLite API,如果有)
解决方案
似乎此模型中有不受支持的操作。
您可以在这里找到预训练的“COCO SSD MobileNet v1”tflite 模型
推荐阅读
- c++ - 带有记录器策略的模板类,用于在编译时启用或禁用日志记录
- c++ - 什么是 C++ 中的“进程被杀死”?
- c# - 我想将计算机视觉 api 结果发布到网页中
- python - Python - asyncio - 从未检索到任务异常
- python - 如何将 csv 文件输入到 Pygal 条形图中
- amazon-s3 - Cloudformation - 向 SQS 发送现有存储桶的 s3 通知
- regex - 匹配完整的重复模式
- xml - 使用 XSLT 将 XML 转换为 SOAP 输出
- visual-studio-code - VSCode 只显示一个关于片段或 emmet 的建议
- python - 通过正则表达式将熊猫数据框列拆分为 2