サンプルの実行(RaspberryPi編)

環境構築が終わった後は、サンプルを実行してみましょう。

認識させたい画像は、ぱくたそ(https://www.pakutaso.com)から借用しました。

本記事は、https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_raspbian.html
を元に記述しています。元のページも参照してください。

Build and Run Object Detection Sample

1. 書き込み権限があるディレクトリ(home/piなど)で、ビルド用のディレクトリを作成します。この例では、buildという名前のフォルダを使います。

mkdir build && cd build

2. 物体認識のサンプルをビルドします。
==============
★英語のドキュメントでは、samples配下のcフォルダの指定が抜けているので注意してください。
==============

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples/c
 cd object_detection_sample_ssd/
 make -j2
 [ 50%] Built target opencv_c_wraper
 [100%] Built target object_detection_sample_ssd_c

3. トレーニング済の顔認識モデルをダウンロードか、コピーします。

==============
★英語のドキュメント通りにすると、サンプル実行時にエラーになりました。
以下の情報によると既知の問題で、以前のトレーニング済モデルを使って回避との事です。 

https://software.intel.com/en-us/node/849460
Error when running demo when installing Openvino on Raspberry Pi

This is a known issue with the latest OpenVINO™ toolkit version (2020.1). The "axis" error is caused by the new IR v10 format.
Try using the pre-trained model from the previous release:
wget https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_mo...
https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_mo...
============== 
pi@raspberrypi:~/build $ wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
 pi@raspberrypi:~/build $ wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-adas-0001/FP16/face-detection-adas-0001.bin

4. サンプルを実行します。

./armv7l/Release/object_detection_sample_ssd_c -m face-detection-adas-0001.xml -d MYRIAD -i <入力ファイル>
使用した入力ファイル
https://www.pakutaso.com/20191209360post-21711.html

結果は、out_0.bmpというファイルが作成されるので、確認してください。

実行結果。顔を認識している事が確認できます。

Run Inference of Face Detection Model Using OpenCV API

1. トレーニング済の顔認識モデルをダウンロードか、コピーします。

★上記の通り、英語のドキュメント通りにすると、サンプル実行時にエラーになりました。
1つ前のモデルを利用します。

pi@raspberrypi:~/build $ wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
pi@raspberrypi:~/build $ wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-adas-0001/FP16/face-detection-adas-0001.bin

2. openvino_fd_myriad.py というファイルを作成して、以下のスクリプト をコピーしてください。
スクリプト 実行前に、frame = cv.imread(‘/path/to/image’) に読み込む画像ファイルに修正してください。

import cv2 as cv 
 Load the model.
 net = cv.dnn_DetectionModel('face-detection-adas-0001.xml',
 'face-detection-adas-0001.bin')
 Specify target device.
 net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
 Read an image.
 frame = cv.imread('/path/to/image')
 if frame is None:
 raise Exception('Image not found!') 
 Perform an inference.
 _, confidences, boxes = net.detect(frame, confThreshold=0.5) 
 Draw detected faces on the frame.
 for confidence, box in zip(list(confidences), boxes):
 cv.rectangle(frame, box, color=(0, 255, 0)) 
 Save the frame to an image file.
 cv.imwrite('out.png', frame)

3. スクリプト を実行します

python3 openvino_fd_myriad.py

結果は、out.pngというファイルが作成されるので、確認してください。

実行結果。顔を認識している事が確認できます。

サンプルが実行できる事が確認できたら、OpenVINO™ toolkit for Raspbian* OS のインストールは完了です。