手动把用object detection api 自训练的ssd_mobilenet_v2 模型转成openvino环境下的模型
前提:
ubuntu 18.04
安装好openvino,tensorflow1.14.0
假设前奏都已经完成,直接到模型转换情景。
进入官方提供的模型转换脚本目录
cd /opt/intel/openvino/deployment_tools/model_optimizer
在参考了众多前人的博客后,最初的转换命令为:
python3 mo_tf.py --input_model /path/to/model/frozen_inference_graph.pb --output=detection_boxes,detection_scores,num_detections -o /path/to/output/ --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/ssd_support_api_v1.14.json --tensorflow_object_detection_api_pipeline_config /path/to/model_config/pipeline.config
但是报错:
Exception occurred during running replacer “REPLACEMENT_ID” ():
Stopped shape/value propagation at “Postprocessor/Cast_1” node. For
more information please refer to Model Optimizer FAQ
google到了解决方法
翻了n多人的建议(经验)帖之后,终于找到一个靠谱的命令,再试一下(dbq原作者,我忘记了从哪里看的了,所以没法放链接。)
python3 mo_tf.py --input_model /path/to/model/frozen_inference_graph.pb --output=detection_boxes,detection_scores,num_detections -o /path/to/output/ --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/ssd_support_api_v1.14.json --tensorflow_object_detection_api_pipeline_config /path/to/model_config/pipeline.config -b 1 --data_type FP16 --reverse_input_channels
但是仍然报错
想了一下,由于模型是几个月前训练好的,训练时候的pipeline.config已经找不到。拿的官方pipeline.config模板,但是识别类别很不一样,所以改回我训练的类别数就,欧克啦。nice。
上述都成功了之后,准备测试生成的模型文件,但是python一直报错。
ModuleNotFoundError: No module named ‘openvino’
是因为没有运行setupvars.sh,把它加到.bashrc里自启动就行了。
报错记录:
[ ERROR ] Exception occurred during running replacer “REPLACEMENT_ID” (<class ‘extensions.middle.PartialInfer.PartialInfer’>): Stopped sha/value propagation at “Postprocessor/ToFloat” node.
the proposed fix ( “Postprocessor/ToFloat” replacing with
“Postprocessor/Cast”)
ssd的json文件选错了,应该用ssd_v2*.json.
成功的运行命令如下:
python mo_tf.py --input_model /path/to/pb/frozen_inference_graph.pb \
--output detection_boxes,detection_scores,num_detections -o /path/to/output/ \
--tensorflow_use_custom_operations_config extensions/front/tf/ssd_v2_support.json \
--tensorflow_object_detection_api_pipeline_config /path/to/ssd_mobilenet_v2_coco.config -b 1 \
--data_type FP32 --reverse_input_channels