Author: Yang Xuefeng, Intel IoT Industry Innovation Ambassador
Table of contents
1.2 Export YOLOv8-Pose pose estimation OpenVINO IR model
1.4 Write YOLOv8-Pose pose estimation model reasoning program using OpenVINO Python API
1.1 Introduction
" Using OpenVINO to Accelerate the YOLOv8-Seg Instance Segmentation Model on the Intel Development Kit " introduces the deployment and evaluation of the YOLOv8-Seg instance segmentation model using the OpenVINO™ development kit on the Intel Development Kit. This article will introduce the use on the Intel Developer Kit OpenVINO™ 2023.0 accelerates the YOLOv8-Pose pose estimation (Pose Estimation) model.
Please download the sample code warehouse of this article first, and build the OpenVINO reasoning program development environment of YOLOv8 .
git clone https://gitee.com/ppov-nuc/yolov8_openvino.git
1.2 Export YOLOv8-Pose attitude estimation OpenVINO IR model
There are five pose estimation models for YOLOv8-Pose, which are trained in the COCO Keypoints dataset , as shown in the table below.
First use the command: yolo export model=yolov8n-pose.pt format=onnx to complete the export of the yolov8n-pose.onnx model, as shown in the figure below.
Then use the command: mo -m yolov8n-pose.onnx --compress_to_fp16 to optimize and export the OpenVINO IR format model with FP16 precision, as shown in the figure below.
1.3 Use benchmark_app to test the inference computing performance of the yolov8 pose estimation model
benchmark_app is an AI model inference computing performance test tool that comes with the OpenVINOTM tool suite . It can be specified on different computing devices, in synchronous or asynchronous mode, to test the pure AI model inference computing performance without pre- and post-processing.
Use the command: benchmark_app -m yolov8n-pose.xml -d GPU to obtain the asynchronous inference computing performance of the yolov8n-pose.xml model on the integrated graphics card of the Intel Developer Kit , as shown in the figure below.
1.4 Write YOLOv8-Pose pose estimation model reasoning program using OpenVINO Python API
Open yolov8n-seg.onnx with Netron to see the input and output of the model:
- Input node name: " images"; data: float32[1,3,640,640]
- The name of the output node 1: "output0"; data: float32[1,56,8400], where "8400" refers to the 3 detection heads of YOLOv8 when imgsz=640, there are 640/8=80, 640/16= 40, 640/32=20, 80x80+40x40+20x20=8400 output cells; "56" refers to the center coordinates cx, cy, w, h of the "Person" class + the confidence score of the "Person" class + the "Person" class The 17 keypoints of ([17,3]) = 56.
The core source code of the YOLOv8 instance segmentation model sample program yolov8_pose_ov_sync_infer_demo.py based on the OpenVINO Python API is as follows:
# 实例化Core对象
core = Core()
# 载入并编译模型
net = core.compile_model(f'{MODEL_NAME}.xml', device_name="GPU")
# 获得模型输出节点
output_node = net.outputs[0]
ir = net.create_infer_request()
cap = cv2.VideoCapture("store-aisle-detection.mp4")
while True:
start = time.time()
ret, frame = cap.read()
if not ret:
break
[height, width, _] = frame.shape
length = max((height, width))
image = np.zeros((length, length, 3), np.uint8)
image[0:height, 0:width] = frame
scale = length / 640
blob = cv2.dnn.blobFromImage(image, scalefactor=1 / 255, size=(640, 640), swapRB=True)
# 基于OpenVINO实现推理计算
outputs = ir.infer(blob)[output_node]
outputs = np.array([cv2.transpose(outputs[0])])
rows = outputs.shape[1]
# Postprocess
boxes = []
scores = []
preds_kpts = []
for i in range(rows):
classes_scores = outputs[0][i][4]
key_points = outputs[0][i][5:]
if classes_scores >= 0.5:
box = [
outputs[0][i][0] - (0.5 * outputs[0][i][2]), outputs[0][i][1] - (0.5 * outputs[0][i][3]),
outputs[0][i][2], outputs[0][i][3]]
boxes.append(box)
scores.append(classes_scores)
preds_kpts.append(key_points)
result_boxes = cv2.dnn.NMSBoxes(boxes, scores, 0.25, 0.45, 0.5)
detections = []
for i in range(len(result_boxes)):
index = result_boxes[i]
box = boxes[index]
pred_kpts = preds_kpts[index]
detection = {
'class_id': 0,
'class_name': 'person',
'confidence': scores[index],
'box': box,
'scale': scale}
detections.append(detection)
print(box[0] * scale, box[1] * scale, scale)
draw_bounding_box(frame, 0, scores[index], round(box[0] * scale), round(box[1] * scale),
round((box[0] + box[2]) * scale), round((box[1] + box[3]) * scale))
draw_key_points(frame, pred_kpts, 0.2, scale)
The running result is shown in the figure below:
1.5 Conclusion:
With the help of the integrated graphics of the N5105 processor (24 execution units) and OpenVINO 2023.0 , the Intel Developer Kit can achieve quite good performance on the pose estimation model of YOLOv8-Pose. Through asynchronous processing and AsyncInferQueue , the utilization rate of computing equipment can be further improved, and the throughput of AI reasoning programs can be improved.