如何从已保存的模型生成tflite?

4
我想创建一个基于重新训练的ssd_mobilenet模型的目标检测应用程序,就像这位youtuber所做的一样。
我选择了来自Tensorflow Model Zoo的模型ssd_mobilenet_v2_coco。在重新训练过程中,我得到了以下结构的模型:
- 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)

有没有解决"Check failed: dim_size >= 1 (0 vs. 1)"的方案?

1个回答

1

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

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


1
看起来使用'--add_postprocessing_op=true'可以解决这个问题。 - ChrisG

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接