在树莓派+Intel NCS2上跑YoloV3 Tiny

上一篇:树莓派3B+安装OpenVINO,Intel Movidius神经计算棒NCS2的环境部署
二话不说,先放官方教程,不记得从官网的哪个页面下载的了,存在百度网盘,提取码:76zd 。

1. 将Yolo V3的.weights文件转为OpenVINO的IR模型

OpenVINO不支持直接使用Yolo V3的.weights文件,目前仅支持ONNX、TensorFlow、Caffe和MXNet。需要先把.weights文件转换成TensorFlow的.pb文件。

1.1 .weights文件

如果没有现成的,可以从pjreddie网站下载
Yolo V3 COCO weights(237MB),Tiny Yolo V3 COCO weights(34MB) 标签文件 coco.names 下载命名为 tiny_yolov3.labels

1.2 找一个YoloV3的TensorFlow实现

官方文档里面推荐的是 https://github.com/mystic123/tensorflow-yolo-v3。

git clone https://github.com/mystic123/tensorflow-yolo-v3.git

1.3 转换

在Windows下执行

python tensorflow-yolo-v3/convert_weights_pb.py --weights_file yolov3-tiny.weights --class_names tiny_yolov3.labels  --tiny True --size 416 --data_format NHWC --output_graph tiny_yolov3.pb 

编写一个新文件tiny_yolo_v3.json,内容为

[
  {
    "id": "TFYOLOV3",
    "match_kind": "general",
    "custom_attributes": {
      "classes": 80,
      "coords": 4,
      "num": 9,
      "mask": [0, 1, 2],
      "entry_points": ["detector/yolo-v3-tiny/Reshape", "detector/yolo-v3-tiny/Reshape_4"]
    }
  }
]

为什么这里mask只取0,1,2后面再研究。

在windows下执行

python C:\Intel\computer_vision_sdk\deployment_tools\model_optimizer\mo_tf.py --input_shape [1,416,416,3] -m tiny_yolov3.pb --reverse_input_channels --tensorflow_use_custom_operations_config tiny-yolov3.json -n tiny_yolov3 --data_type FP16 

生成 tiny_yolov3.bintiny_yolov3.xml ,将其和 tiny_yolov3.labels 一起上传到树莓派。

测试视频:歌曲《Yolo》

测试
obj_detection_demo_yolov3_tiny_async -i YOLOTheSong_x264.mp4 -m tiny_yolov3.xml -d MYRIAD
效果不太好,5fps左右,识别准确度也不行。以后再优化。
实际应用的时候考虑不用视频,而是直接拍照处理。

猜你喜欢

转载自blog.csdn.net/weixin_41665225/article/details/86519032
今日推荐