目录
1、下载权重
2、python 推理
3、转ONNX格式
4、ONNX RUNTIME C++ 部署
1、下载权重
我这里之前在做实例分割的时候,项目已经下载到本地,环境也安装好了,只需要下载pose的权重就可以
2、python 推理
yolo task=pose mode=predict model=yolov8n-pose.ptsource=0show=true
3、转ONNX格式
yolo export model=yolov8n-pose.pt format=onnx
输出:
(yolo) jason@honor:~/PycharmProjects/pytorch_learn/yolo/ultralytics-main-yolov8$ yolo export model=yolov8n-pose.pt format=onnxUltralytics YOLOv8.0.94Python-3.8.13 torch-2.0.0+cu117 CPUYOLOv8n-pose summary (fused): 187 layers, 3289964 parameters, 0 gradients, 9.2 GFLOPsPyTorch: starting from yolov8n-pose.pt with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 56, 8400) (6.5 MB)ONNX: starting export with onnx 1.13.1 opset 17...============= Diagnostic Run torch.onnx.export version 2.0.0+cu117 =============verbose: False, log level: Level.ERROR======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================ONNX: export success ✅ 0.8s, saved as yolov8n-pose.onnx (12.9 MB)Export complete (1.4s)Results saved to /home/jason/PycharmProjects/pytorch_learn/yolo/ultralytics-main-yolov8Predict: yolo predict task=pose model=yolov8n-pose.onnx imgsz=640 Validate:yolo val task=pose model=yolov8n-pose.onnx imgsz=640 data=/usr/src/app/ultralytics/datasets/coco-pose.yaml Visualize: https://netron.app
用netron查看一下:
如上图所是,YOLOv8n-pose只有一个输出:
output0: float32[1,56,8400]。这里的8400,表示有8400个检测框,56为4边界框坐标信息+人这个类别预测分数,17*3关键点信息。每个关键点由x,y,v组成,v代表该点是否可见,v小于 0.5 时,表示这个关键点可能在图外,可以考虑去除掉。
COCO的annotation一共有17个关节点。
分别是:“nose”,“left_eye”, “right_eye”,“left_ear”, “right_ear”,“left_shoulder”, “right_shoulder”,“left_elbow”, “right_elbow”,“left_wrist”, “right_wrist”,“left_hip”, “right_hip”,“left_knee”, “right_knee”,“left_ankle”, “right_ankle”。示例图如下:
4、ONNX RUNTIME C++ 部署
第二篇参考文章的github项目,以此为参考,实现ONNX RUNTIME C++部署
视频输入,效果如下:
参考:
Yolov8 姿态估计 – 知乎
YOLOv8-Pose 的 TensorRT8 推理尝试 – 知乎