我正在尝试在 Android 上运行 tflite 模型以进行对象检测。对于相同的,
(a) 培训:
!python3 object_detection/model_main.py \
--pipeline_config_path=/content/drive/My\ Drive/Detecto\ Tutorial/models/research/object_detection/samples/configs/ssd_mobilenet_v2_coco.config \
--model_dir=training/
Run Code Online (Sandbox Code Playgroud)
(修改配置文件以指向提到我的特定 TFrecords 的位置)
(b) 导出推理图
!python /content/drive/'My Drive'/'Detecto Tutorial'/models/research/object_detection/export_inference_graph.py \
--input_type=image_tensor \
--pipeline_config_path=/content/drive/My\ Drive/Detecto\ Tutorial/models/research/object_detection/samples/configs/ssd_mobilenet_v2_coco.config \
--output_directory={output_directory} \
--trained_checkpoint_prefix={last_model_path}
Run Code Online (Sandbox Code Playgroud)
(c) 创建 tflite 就绪图
!python /content/drive/'My Drive'/'Detecto Tutorial'/models/research/object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path=/content/drive/My\ Drive/Detecto\ Tutorial/models/research/object_detection/samples/configs/ssd_mobilenet_v2_coco.config \
--output_directory={output_directory} \
--trained_checkpoint_prefix={last_model_path} \
--add_postprocessing_op=true
Run Code Online (Sandbox Code Playgroud)
我使用图形文件中的 tflite_convert 创建了一个 tflite 模型,如下所示
!tflite_convert
--graph_def_file=/content/drive/My\ Drive/Detecto\ Tutorial/models/research/fine_tuned_model/tflite_graph.pb
--output_file=/content/drive/My\ Drive/Detecto\ Tutorial/models/research/fine_tuned_model /detect3.tflite
--output_format = 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', …