python-3.x - 如何从保存的模型生成 tflite?

标签 python-3.x tensorflow object-detection object-detection-api tensorflow-lite

我想创建一个基于重新训练的 ssd_mobilenet 模型的对象检测应用程序,我像 youtube 上的那个人一样重新训练过。 .

我选的型号ssd_mobilenet_v2_coco来自 Tensorflow Model Zoo .在重新训练过程之后,我得到了具有以下结构的模型:

- saved_model
    - variables (empty folder)
    - saved_model.pb
- checkpoint
- frozen_inverence_graph.pb
- model.ckpt.data-00000-of-00001
- model.ckpt.index
- model.ckpt.meta
- pipeline.config

在同一个文件夹中,我有带有以下代码的 python 脚本:

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model("saved_model", input_shapes={"image_tensor":[1,300,300,3]})
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

运行此代码后,我收到以下错误:
...
2019-05-24 18:46:59.811289: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayGatherV3
2019-05-24 18:46:59.811864: I tensorflow/lite/toco/import_tensorflow.cc:1373] Unable to determine output type for op: TensorArrayGatherV3
2019-05-24 18:46:59.908207: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 1792 operators, 3033 arrays (0 quantized)
2019-05-24 18:47:00.089034: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 1771 operators, 2979 arrays (0 quantized)
2019-05-24 18:47:00.314681: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 1771 operators, 2979 arrays (0 quantized)
2019-05-24 18:47:00.453570: F tensorflow/lite/toco/graph_transformations/resolve_constant_slice.cc:59] Check failed: dim_size >= 1 (0 vs. 1)

“检查失败:dim_size >= 1 (0 vs. 1)”有什么解决方案吗?

最佳答案

由于图中需要一些自定义操作,MobileNet SSD 的转换略有不同。

看看这个Medium post用于训练和将模型导出为 TFLite 图的端到端过程。对于转换,您需要使用 export_tflite_ssd_graph脚本。

关于python-3.x - 如何从保存的模型生成 tflite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56296724/

相关文章:

python重命名多列和汇总数据框

python - Golang 可以像 Python 那样将字符串相乘吗?

python-3.x - 形状 (1,) 和 () 在条件运算符上不兼容

python - 如何在 pdb 中使用 'debug' 命令(python)

python-3.x - OpenSUSE 上的 Python 中未显示绘图

Python -> Boost Python + C++ 错误

python - 将 tensorflow 张量列解包到单独的变量中

deep-learning - YOLOv4 中的损失和 mAP 图表

python-3.x - 有什么方法可以在 Windows 10 上的 anaconda 中导入 easydict

Tensorflow 对象检测,生成 tfrecord 时出错 [TypeError : None has type NoneType,,但预期为 : int, 长之一]