< >
Home » ROS2与深度学习教程 » ros2与深度学习教程-整合物体检测(ssd_mobilenet_v2_coco)

ros2与深度学习教程-整合物体检测(ssd_mobilenet_v2_coco)

ros2与深度学习教程-整合物体检测(ssd_mobilenet_v2_coco)

说明: 

  • 介绍如何整合Openvino使用ssd_mobilenet_v2_coco模型

步骤:

  • 依赖tensorflow,如果没先安装
pip install tensorflow
  • 需要下载例子对应的模型文件
cd /opt/openvino_toolkit/models/
sudo python3 downloader.py --name ssd_mobilenet_v2_coco 
  • 下载到目录/opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco
  • ssd_mobilenet_v2_coco是Tensorflow模型,需要转换
sudo chmod -R 777 /opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco
python3 converter.py --name=ssd_mobilenet_v2_coco --mo /opt/intel/openvino_2021/deployment_tools/model_optimizer/mo.py
  • 制作label文件, 从模型说明,了解到这个分类类别在文件<omz_dir>/data/dataset_classes/coco_91cl_bkgr.txt
  • 对应我们安装openvino的目录
/opt/intel/openvino_2021/deployment_tools/open_model_zoo/data/dataset_classes
  • 复制修改
sudo cp /opt/intel/openvino_2021/deployment_tools/open_model_zoo/data/dataset_classes/coco_91cl_bkgr.txt /opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco/FP16/ssd_mobilenet_v2_coco.labels
  • 去掉ssd_mobilenet_v2_coco.labels文件,第一行的内容
  • 具体内容如下
person
bicycle
car
motorcycle
airplan
bus
train
truck
boat
traffic light
fire hydrant
street sign
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
hat
backpack
umbrella
shoe
eye glasses
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
plate
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
couch
potted plant
bed
mirror
dining table
window
desk
toilet
door
tv
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
blender
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
hair brush
  • 并修改代码包里ros2_openvino_toolkit/sample/param目录下pipeline_object.launch.py对应的配置文件pipeline_object.yaml
  • 修改如下
Pipelines:
- name: object
  inputs: [StandardCamera]
  infers:
    - name: ObjectDetection
      model: /opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco/FP16/ssd_mobilenet_v2_coco.xml
      engine: CPU
      label: /opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco/FP16/ssd_mobilenet_v2_coco.labels
      batch: 1
      confidence_threshold: 0.5
      enable_roi_constraint: true # set enable_roi_constraint to false if you don't want to make the inferred ROI (region of interest) constrained into the camera frame
  outputs: [ImageWindow, RosTopic]
  connects:
    - left: StandardCamera
      right: [ObjectDetection]
    - left: ObjectDetection
      right: [ImageWindow]
    - left: ObjectDetection
      right: [RosTopic]

OpenvinoCommon:

测试: 

  • 接好usb摄像头
  • 新开终端,执行命令
#run face detection sample code input from StandardCamera.
ros2 launch dynamic_vino_sample pipeline_object.launch.py
  • 查看话题
ros2 run rqt_image_view rqt_image_view

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2与深度学习教程