[英]Failing to convert .pb graph to tflite
I am creating a custom object detection sample for android, I used the ssd_mobilenet_v1_coco
pretrained model for transfer learning and got a decent accuracy.我正在为 android 创建一个自定义 object 检测样本,我使用
ssd_mobilenet_v1_coco
预训练的 model 进行迁移学习,并获得了不错的准确性。 I also successfully managed to export the model.ckpt-XXXX
to a .pb
tflite graph using this line of code in the terminal (ran from the object_detection folder after cloning Tensorflow Object Detection API from github): I also successfully managed to export the
model.ckpt-XXXX
to a .pb
tflite graph using this line of code in the terminal (ran from the object_detection folder after cloning Tensorflow Object Detection API from github):
python export_tflite_ssd_graph.py --pipeline_config_path=training/ssd_mobilenet_v1_coco.config --trained_checkpoint_prefix=training/model.ckpt-40500--output_directory=tflite --add_postprocessing_op=true
The above created a folder tflite
and it contained 2 files:上面创建了一个文件夹
tflite
,它包含 2 个文件:
However, when I want to convert the tflite_graph.pb
to detect.tflite
I get the following error and the program ends abruptly:但是,当我想将
tflite_graph.pb
转换为detect.tflite
时,出现以下错误并且程序突然结束:
"TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: TOCO failed.
.
.
.
Check failed: input_array_dims[i] == input_array_proto.shape().dims(i) (300 vs. 128)
Fatal Python error: Aborted
.
.
.
This is the command I used to convert the .pb
to .tflite
:这是我用来将
.pb
转换为.tflite
的命令:
tflite_convert --graph_def_file=tflite/tflite_graph.pb --output_file=tflite/detect.tflite --input_shapes=1,128,128,3 --input_arrays=normalized_input_image_tensor --output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 --allow_custom_ops
The images I used had a size of 128x128 hence why I assumed that would be the input_shapes.我使用的图像大小为 128x128,因此我认为这将是 input_shapes。 I do have Toco installed as well.
我也安装了 Toco。
Any help or advice will be highly appreciated.任何帮助或建议将不胜感激。
So upon doing additional research, I found out that it was because the config file of the model was looking at images of sizes 300 x 300. So I changed the images dimension in the config file to 128 and it worked.因此,在进行额外研究后,我发现这是因为 model 的配置文件正在查看尺寸为 300 x 300 的图像。所以我将配置文件中的图像尺寸更改为 128 并且它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.