之前有寫過 OpenVINO 的介紹與安裝教學,本文要來介紹 Intel NCS2 神經運算棒
Intel Neural Compute Stick 2 (NCS2) 是一款外型類似 USB 的神經網路運算裝置,內建 Intel Movidius Myriad X VPU 處理器,可提升5~8倍推理運算速度
使用方式與 USB 一樣,隨插即用,可廣泛用於邊緣設備上,支援 Intel 設備與樹莓派,能夠搭配 OpenVINO 深度學習開發套件來進行推理運算
接下來要來講如何使用 NCS2 進行推論~
我使用的作業系統為 WIindows10, CUDA 10.0, cuDNN 7.6.5 版本。可以從官方 github 查看哪些 code 支援 NCS2: Inference Engine Demos
本文使用筆電做示範,將 NCS2 插入隨身碟讀取的位置,可以看到電腦已出現 Movidius MyraidX 裝置
之前的 OpenVINO 安裝教學是使用 2019R2 版本,但因為較多的 python demo code 是從 2020 版本後才有提供,因此本文採用 openvino_2020.3.194 版本
若要解除安裝之前的 OpenVINO 版本,到應用程式與功能中將其解除安裝即可
所有 python demo code 會放在 C:\Program Files (x86)\IntelSWTools\openvino\inference_engine\demos\python_demos 資料夾裡
首先要設定 OpenVINO 的環境。開啟 cmd ,進入至 C:\Program Files (x86)\IntelSWTools\openvino\bin
$ cd C:\Program Files (x86)\IntelSWTools\openvino\bin# 執行
$ setupvars.bat
Python demo: Interactive Face Recognition
官方說明文件: https://docs.openvinotoolkit.org/2020.1/_demos_python_demos_face_recognition_demo_README.html
- 下載模型的指令為
python downloader.py --name <model> --output_dir <dir_path>
- 人臉識別的模型有四種:
🔹 face-detection-retail-0004 及 face-detection-adas-0001 用來偵測人臉
🔹 landmarks-regression-retail-0009 預測人臉的 keypoints
🔹 face-reidentification-retail-0095 識別人
- 下載模型
$ cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\tools\model_downloader$ python downloader.py — name face-detection-adas-0001 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py — name face-detection-retail-0004 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py — name landmarks-regression-retail-0009 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py — name face-reidentification-retail-0095 --output_dir C:\Users\joyle\Documents\Intel\model
- 進入至 face_recognition_demo
$ cd C:\Program Files (x86)\IntelSWTools\openvino_2020.3.194\deployment_tools\inference_engine\demos\python_demos\face_recognition_demo
- 在 face_recognition_demo 資料夾設置人臉資料庫
$ mkdir face_gallery
將想識別的人的照片放入此資料夾中,命名方式為 person_name.jpg 或是 person_name.png
若是同一個人的照片有很多張則命名為 person_name-{num}.jpg
- 執行識別人臉~
🔸 預設為開啟鏡頭 (-i cam),也可以使用 -i <video_path>
🔸 -fg 為設定人臉資料庫路徑, --run_detector 為將人臉照片加入資料庫
🔸 人臉偵測模型可以使用 face-detection-retail-0004 或是 face-detection-adas-0001
🔸 -d_fd, -d_lm, -d_reid 為要使用何種 device,可以設置 CPU, GPU, FPGA, MYRIAD, HETERO, HDDL,這邊示範使用 NCS2,因此要設定為 MYRIAD
🔸 --verbose 為是否輸出訊息
$ python face_recognition_demo.py -fg “face_gallery” --run_detector -m_fd C:\Users\joyle\Documents\Intel\model\intel\face-detection-retail-0004\FP16\face-detection-retail-0004.xml -m_lm C:\Users\joyle\Documents\Intel\model\intel\landmarks-regression-retail-0009\FP16\landmarks-regression-retail-0009.xml -m_reid C:\Users\joyle\Documents\Intel\model\intel\face-reidentification-retail-0095\FP16\face-reidentification-retail-0095.xml -d_fd MYRIAD -d_lm MYRIAD -d_reid MYRIAD --verbose# 使用 face-detection-adas-0001 模型
$ python face_recognition_demo.py -fg “face_gallery” --run_detector -m_fd C:\Users\joyle\Documents\Intel\model\intel\face-detection-adas-0001\FP16\face-detection-adas-0001.xml -m_lm C:\Users\joyle\Documents\Intel\model\intel\landmarks-regression-retail-0009\FP16\landmarks-regression-retail-0009.xml -m_reid C:\Users\joyle\Documents\Intel\model\intel\face-reidentification-retail-0095\FP16\face-reidentification-retail-0095.xml -d_fd MYRIAD -d_lm MYRIAD -d_reid MYRIAD --verbose
執行過程會先出現資料庫的人臉照片,輸入人物名字後按 enter,等待一下子就會開啟鏡頭預測或是輸出影片預測
C++ demo: Interactive Face Detection
官方說明文件: https://docs.openvinotoolkit.org/2020.1/_demos_python_demos_face_recognition_demo_README.html
- 下載模型的指令為
python downloader.py — name <model> — output_dir <dir_path>
- 人臉偵測的模型有四種:
🔹 face-detection-adas-0001 用來偵測人臉
🔹 age-gender-recognition-retail-0013 估計人臉的年齡和性別
🔹 head-pose-estimation-adas-0001 估計頭部角度
🔹 emotions-recognition-retail-0003 檢測臉部情緒
🔹 facial-landmarks-35-adas-0002 估計臉部 landmark
- 下載模型
$ cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\tools\model_downloader$ python downloader.py --name age-gender-recognition-retail-0013 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py --name head-pose-estimation-adas-0001 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py --name emotions-recognition-retail-0003 --output_dir C:\Users\joyle\Documents\Intel\model$ python downloader.py --name facial-landmarks-35-adas-0002 --output_dir C:\Users\joyle\Documents\Intel\model
- 進入編譯過的 demo 資料夾
$ cd C:\Users\joyle\Documents\Intel\OpenVINO\omz_demos_build\intel64\Release
- 執行 interactive_face_detection_demo~
可以不用輸入全部的模型,依照想偵測的項目輸入即可,但一定要輸入人臉偵測模型 face-detection-adas-0001,這邊一定要設定輸入項目 -i cam 或 -i <video_path>,這邊示範 device 設定為 MYRIAD
$ interactive_face_detection_demo -i cam -m C:\Users\joyle\Documents\Intel\model\intel\face-detection-adas-0001\FP16\face-detection-adas-0001.xml -m_ag C:\Users\joyle\Documents\Intel\model\intel\age-gender-recognition-retail-0013\FP16\age-gender-recognition-retail-0013.xml -m_hp C:\Users\joyle\Documents\Intel\model\intel\head-pose-estimation-adas-0001\FP16\head-pose-estimation-adas-0001.xml -m_em C:\Users\joyle\Documents\Intel\model\intel\emotions-recognition-retail-0003\FP16\emotions-recognition-retail-0003.xml -m_lm C:\Users\joyle\Documents\Intel\model\intel\facial-landmarks-35-adas-0002\FP16\facial-landmarks-35-adas-0002.xml -d MYRIAD