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

时间:2019-05-24 16:53:02

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

我想基于经过重新训练的ssd_mobilenet模型(类似于youtube上的那个家伙)创建对象检测应用。

我从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)

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

1 个答案:

答案 0 :(得分:0)

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

请查看此Medium post,了解训练模型并将其导出为TFLite图的端到端过程。要进行转换,您需要使用export_tflite_ssd_graph脚本。

相关问题