空飛ぶロボットのつくりかた

ロボットをつくるために必要な技術をまとめます。ロボットの未来についても考えたりします。

はじめてのROSでOpenVINO - インストール〜サンプル実行まで

f:id:robonchu:20190624060141p:plain

やりたいこと

  • CPUリソースで認識機能(顔検出や姿勢推定など)をそこそこの検出速度(10~30FPSくらい)で使いたい

  • ROS x OpenVINOを動かしてみる

環境

  • OS: Ubuntu18.04

  • Middleware: ROS1 melodic

  • CPU: Intel® Core™ i7-8650U CPU @ 1.90GHz × 8

使用するパッケージは⤵

GitHub - intel/ros_openvino_toolkit

ROS x OpenVINOのデザインアーキ

f:id:robonchu:20190624064728p:plain
https://github.com/intel/ros_openvino_toolkit

実装されている認識機能

  1. Face Detection
  2. Emotion Recognition
  3. Age & Gender Recognition
  4. Head Pose Estimation
  5. Object Detection
  6. Vehicle Detection
  7. Object Segmentation
  8. Person Reidentification

インストール&各種設定

環境設定

手順は以下に沿って行う

流れを順に説明⤵

  1. ros_openvino_toolkitのインストール

    git clone https://github.com/intel/ros_openvino_toolkit.git

  2. セットアップスクリプトの実行

    • cd ~/ros_openvino_toolkit/script

    • ./environment_setup.sh

    • 内容の変更は同フォルダのmodules.conf(以下参照)をいじる。0すると無効。

      clean=1

      ros_debian=0

      opencv=1

      opencl=1

      dldt=1

      model_zoo=1

      openvino=1

      librealsense=0

      other_dependency=0

  3. 環境変数の設定(set ENV InferenceEngine_DIR, CPU_EXTENSION_LIB and GFLAGS_LIB)

    • export InferenceEngine_DIR=/opt/openvino_toolkit/dldt/inference-engine/build/

    • export CPU_EXTENSION_LIB=/opt/openvino_toolkit/dldt/inference-engine/bin/intel64/Release/lib/libcpu_extension.so

    • export GFLAGS_LIB=/opt/openvino_toolkit/dldt/inference-engine/bin/intel64/Release/lib/libgflags_nothreads.a

    • 毎回設定したくない人は、以下を.bashrcなどに追記すると良い。  

  4. catkin_make用のworkspace作成

    • mkdir -p ~/catkin_ws/src

    • cd ~/catkin_ws/src

    • git clone https://github.com/intel/ros_openvino_toolkit

    • git clone https://github.com/intel/object_msgs

    • git clone https://github.com/ros-perception/vision_opencv

    • git clone https://github.com/intel-ros/realsense

    • cd realsense

    • git checkout 2.1.3

  5. パッケージのビルドとリンク

    • source /opt/ros/melodic/setup.bash
    • cd ~/catkin_ws
    • catkin_make
    • source devel/setup.bash
    • sudo mkdir -p /opt/openvino_toolkit
    • sudo ln -s ~/catkin_ws/src/ros_openvino_toolkit /opt/openvino_toolkit/ros_openvino_toolkit

ここまで来たらあともう少し

事前準備

GitHub - intel/ros_openvino_toolkitの手順に沿って行う。

訓練済みモデルの変換

Segmentation(Mask-RCNN)を使うための準備。

 cd /opt/openvino_toolkit/dldt/model-optimizer/install_prerequisites
 sudo ./install_prerequisites.sh
 mkdir -p ~/Downloads/models
 cd ~/Downloads/models
 wget http://download.tensorflow.org/models/object_detection/mask_rcnn_inception_v2_coco_2018_01_28.tar.gz
 tar -zxvf mask_rcnn_inception_v2_coco_2018_01_28.tar.gz
 cd mask_rcnn_inception_v2_coco_2018_01_28
 python3 /opt/openvino_toolkit/dldt/model-optimizer/mo_tf.py --input_model frozen_inference_graph.pb --tensorflow_use_custom_operations_config /opt/openvino_toolkit/dldt/model-optimizer/extensions/front/tf/mask_rcnn_support.json --tensorflow_object_detection_api_pipeline_config pipeline.config --reverse_input_channels --output_dir ./output/
 sudo mkdir -p /opt/models
 sudo ln -s ~/Downloads/models/mask_rcnn_inception_v2_coco_2018_01_28 /opt/models/

Detection(MobileNet-SSD)を使うための準備。

  • sudo apt-get install python3-networkx
 cd /opt/openvino_toolkit/open_model_zoo/model_downloader
 python3 ./downloader.py --name mobilenet-ssd
 #FP32 precision model
 sudo python3 /opt/openvino_toolkit/dldt/model-optimizer/mo.py --input_model /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/mobilenet-ssd.caffemodel --output_dir /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/output/FP32 --mean_values [127.5,127.5,127.5] --scale_values [127.5]
 #FP16 precision model
 sudo python3 /opt/openvino_toolkit/dldt/model-optimizer/mo.py --input_model /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/mobilenet-ssd.caffemodel --output_dir /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/output/FP16 --data_type=FP16 --mean_values [127.5,127.5,127.5] --scale_values [127.5]
最適化されたモデルの中間表現をダウンロード
 cd /opt/openvino_toolkit/open_model_zoo/model_downloader
 python3 downloader.py --name face-detection-adas-0001
 python3 downloader.py --name age-gender-recognition-retail-0013
 python3 downloader.py --name emotions-recognition-retail-0003
 python3 downloader.py --name head-pose-estimation-adas-0001
 python3 downloader.py --name person-detection-retail-0013
 python3 downloader.py --name person-reidentification-retail-0076
ラベルファイルのコピー

Segmentation用

 sudo cp /opt/openvino_toolkit/ros_openvino_toolkit/data/labels/object_segmentation/frozen_inference_graph.labels /opt/models/mask_rcnn_inception_v2_coco_2018_01_28/output

Detection用

 sudo cp /opt/openvino_toolkit/ros_openvino_toolkit/data/labels/emotions-recognition/FP32/emotions-recognition-retail-0003.labels /opt/openvino_toolkit/open_model_zoo/model_downloader/Retail/object_attributes/emotions_recognition/0003/dldt
 sudo cp /opt/openvino_toolkit/ros_openvino_toolkit/data/labels/face_detection/face-detection-adas-0001.labels /opt/openvino_toolkit/open_model_zoo/model_downloader/Transportation/object_detection/face/pruned_mobilenet_reduced_ssd_shared_weights/dldt
 sudo cp /opt/openvino_toolkit/ros_openvino_toolkit/data/labels/object_detection/mobilenet-ssd.labels /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/output/FP32
 sudo cp /opt/openvino_toolkit/ros_openvino_toolkit/data/labels/object_detection/mobilenet-ssd.labels /opt/openvino_toolkit/open_model_zoo/model_downloader/object_detection/common/mobilenet-ssd/caffe/output/FP16
環境変数の設定
  • export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openvino_toolkit/dldt/inference-engine/bin/intel64/Release/lib

  • 毎回設定したくない人は、以下を.bashrcなどに追記すると良い。

サンプル実行

パソコンに既存のカメラもしくは指しているUSBカメラ情報を用いた顔認識周りのサンプル

  1. cd ~/catkin_ws/

  2. source devel/setup.bash

  3. roslaunch vino_launch pipeline_people_oss.launch

すると、rvizとImageWindowが立ち上がり結果が表示される。

全力で笑顔を作るとちゃんとHappyに☺

f:id:robonchu:20190624071058p:plain

加工雑すぎ問題...

中身の簡単な解説とFPS

このlaunchは、

  1. 顔検出

  2. 年齢&性別判定

  3. 感情推定

  4. 頭の向き推定

が立ち上がるようになっていて、検出速度は10FPSくらいでてる。

顔検出だけにするとだいだい30FPSまで上がる。

launchファイルはparamディレクトリのyamlファイルを読み込むようになっていて、このyamlにどの認識機能を使うかや何を入力としてどこに出力するか等の設定が書かれている。

所感

CPUリソースだけで処理速度はそこそこ速いので、ラピッドプロトで何かを作る際には便利だと思う。

OpenVINOのROS2パッケージもあるし、OpenVINOは今後も要チェック。

個人の活動はもうそろそろROS2に切り替えていこう。