如何将tfl ite_graph.pb正确转换为detect.tflite

问题描述 投票:0回答:1

我正在使用tensorflow对象检测api来使用来自tensorflow model zoo的ssdlite_mobilenet_v2_coco_2018_05_09训练自定义模型。

我成功地训练了模型,并使用this tutorial中提供的脚本对其进行了测试。

这里是问题,我需要detect.tflite才能在目标计算机(嵌入式系统)中使用它。但是,当我实际上从模型中制作tflite时,它几乎不输出任何内容,而当它出现时,则是错误检测。为了制作.tflite文件,我首先通过以下命令在输出上使用export_tflite_ssd_graph.py,然后在toco上使用此命令,方法是按照the doc和一些Google搜索:

toco --graph_def_file=$OUTPUT_DIR/tflite_graph.pb --output_file=$OUTPUT_DIR/detect.tflite --input_shapes=1,300,300,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

此外,我使用.tflite执行检测任务的代码也正常工作,因为我已使用ssd_mobilenet_v3_small_coco detect.tflite文件对其进行了测试。

python tensorflow object-detection-api tf-lite
1个回答
0
投票

问题出在toco命令。我使用的某些文档已经过时并误导了我。 toco已过时,我应该改用tflite_convert工具。

这是我使用的完整命令:

tflite_convert --graph_def_file tflite_inference_graph / tflite_graph.pb --output_file =。/ detect.tflite --output_format = TFLITE --input_shapes = 1,300,300,3 --input_arrays = normalized_input_image_tensor --output_arrays ='TFLite_Detection_PostProcess,' ,'TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3'--inference_type = QUANTIZED_UINT8 --mean_values = 128 --std_dev_values = 127 --change_concat_input_ranges = false --allow_custom_ops

我对ssdlite_mobilenet_v2_coco_2018_05_09模型进行了培训,并将其添加到我的.config文件末尾。

graph_rewriter {量化{延误:400重量位:8activation_bits:8}}

注意:我想在嵌入式系统上使用量化模型。这就是我在配置文件中添加graph_rewriter并在tflite_convert命令中添加--inference_type = QUANTIZED_UINT8的原因。

© www.soinside.com 2019 - 2024. All rights reserved.