
สวัสดีครับ… วันนี้ผมจะมาพูดถึงอุปกรณ์ Intel Neural Compute Stick 2 เรียกสั้นๆว่า NCS2 เป็นอุปกรณ์ที่ใช้เป็นตัวเร่งการประมวลผลด้าน AI ที่อยู่ในรูปแท่งยูเอสบียอดนิยม โดยเวอร์ชั่นใหม่นี้ ซึ่งก็คือเวอร์ชัน 2 ให้ทั้งประสิทธิภาพที่มากขึ้น รวมทั้งครอบคลุมการนำไปประยุกต์ใช้ได้หลากหลายขึ้น
สำหรับ NCS2 นี้ใช้ชิป Vision Processing Unit (VPU)ตัวล่าสุดในชื่อ Movidius Myriad X VPU ทำให้มีประสิทธิภาพเหนือกว่า NCS รุ่นแรกถึง 8 เท่า รวมทั้งมีชุดเครื่องมือ IntelOpenVINO ที่เปิดให้นักพัฒนาสามารถสร้างและฝึกโมเดล AI บนคลาวด์ได้
ซึ่งในบทความนี้จะเป็นการนำ NCS2 มาใช้กับ Raspberry Pi 4 เรียกย่อๆว่า RPI4 ซึ่งเป็นบอร์ดตัวหนึ่งที่รันแบบมี OS เป็นของตัวเอง เปรียบเสมือนคอมพิวเตอร์จิ๋วตัวหนึ่ง ประสิทธิภาพก็จะมีข้อจำกัดตามขนาด ซึ่งหากเราต้องการใช้ RPI4 รันระบบ AI ก็อาจจะทำให้การประมวลผลนั้นค่อนข้างช้ามาก จึงเป็นที่มาที่เรานำตัว NCS2 มาช่วยในส่วนนี้ครับ
Install NCS2 บน OS ของ RPI4
เริ่มจาก Install Software ที่ใช้ในการติดตั้งครับ
1 2 3 4 5 6 7 8 9 10 11 12 |
# install software sudo apt-get update sudo apt-get install git sudo apt-get install cmake sudo apt-get install libatlas-base-dev sudo apt-get install python3-pip sudo apt install libgtk-3-dev pip3 install --upgrade pip pip3 install numpy |
ดาวน์โหลด Openvino Toolkit เลือกที่เป็นเวอร์ชันสำหรับ Raspberry Pi
แตกไฟล์ที่ดาวน์โหลด แก้ไขชื่อ folder ตามต้องการ ในบทความนี้ผมจะตั้งเป็น openvino_toolkit

รัน Environment ของ Openvino ถ้ารันแล้วสามารถเช็คจากเวอร์ชันของ Opencv ถ้าเป็น Openvino จะเป็น 4.x.x-openvino
1 2 3 4 |
# set environment source /openvino_toolkit/bin/setupvars.sh |
ติดตั้ง USB Rules เพื่อให้ RPI 4 เห็นอุปกรณ์ NCS2 ผ่าน USB
1 2 3 4 5 6 7 |
# add usb rule sudo usermod -a -G users "$(whoami)" sh /openvino_toolkit/install_dependencies/install_NCS_udev_rules.sh cd /etc/udev/rules.d/ cat 97-myriad-usbboot.rules |
ในไฟล์ 97-myriad-usbboot.rules จะต้องมีข้อความตามนี้
1 2 3 4 5 |
SUBSYSTEM=="usb", ATTRS{idProduct}=="2150", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0660", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEM=="usb", ATTRS{idProduct}=="2485", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0660", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEM=="usb", ATTRS{idProduct}=="f63b", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0660", ENV{ID_MM_DEVICE_IGNORE}="1" |
จากนั้นเรามาทำการทดสอบกันครับ สร้างไฟล์ openvino_fd_myriad.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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) |
ดาวน์โหลดไฟล์ weight ที่เป็น .bin
1 2 3 |
wget --no-check-certificate https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1/face-detection-adas-0001/FP16/face-detection-adas-0001.bin |
ดาวน์โหลดไฟล์ .xml
1 2 3 |
wget --no-check-certificate https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1/face-detection-adas-0001/FP16/face-detection-adas-0001.xml |
จากนั้นลองรันด้วยคำสั่ง
1 2 3 |
python3 openvino_fd_myriad.py |
จะได้ไฟล์ out.png ที่เป็นการประมวลผลรูปภาพที่สำเร็จแล้ว ลองเปิดไฟล์เพื่อดูผล

จากนั้นทำการรันทดสอบกับไฟล์วิดิโอกันบ้างครับ รันแบบปกติบน RPI4 แบบไม่ใช้ NCS2 จะได้ FPS ตามด้านล่างครับ
1 2 3 4 5 6 7 8 9 10 |
FPS: 1.15 (excluding drawing time of 32.57ms) FPS: 1.24 (excluding drawing time of 30.59ms) FPS: 1.32 (excluding drawing time of 30.58ms) FPS: 1.24 (excluding drawing time of 31.96ms) FPS: 1.37 (excluding drawing time of 31.31ms) FPS: 1.28 (excluding drawing time of 30.64ms) FPS: 1.28 (excluding drawing time of 30.44ms) FPS: 1.24 (excluding drawing time of 34.44ms) |
ต่อไปลองเสียบ NCS2 แล้วลองรัน Openvino Environment และลองรันโปรแกรมใหม่อีกทีครับ
1 2 3 4 5 6 7 8 9 10 |
FPS: 14.02 (excluding drawing time of 55.95ms) FPS: 18.72 (excluding drawing time of 40.07ms) FPS: 16.93 (excluding drawing time of 40.36ms) FPS: 16.29 (excluding drawing time of 42.52ms) FPS: 16.75 (excluding drawing time of 39.74ms) FPS: 16.54 (excluding drawing time of 41.56ms) FPS: 16.84 (excluding drawing time of 41.47ms) FPS: 19.02 (excluding drawing time of 39.78ms) |
จะเห็นได้ว่า FPS เร็วขึ้นมากถึง 13 เท่าเลยทีเดียวครับ ขอจบเพียงเท่านี้ครับ…
Ref: https://docs.openvinotoolkit.org/2020.1/_docs_install_guides_installing_openvino_raspbian.html
2