赞
踩
早晨看到一堆推文,说YOLOv10已经发布了,吓我一跳,这个世界变化这么快,
然后快速的看一下相关的文档,发现YOLOv10 相比YOLOv8有两个最大的改变分别是 添加了PSA层跟CIB层
去掉了NMS
github上YOLOv10的地址如下
https://github.com/THU-MIG/yolov10
下载源码,直接用下面的代码就可以导出ONNX格式模型了,发现导出以后还没来得及把格式搞清楚,输出得居然是动态得ONNX格式表示,但是实际上
输入支持格式为:1x3x640x640
输出格式为1x300x6
输出格式300是指输出得预测框数目,6分别是
x1 y1 x2 y2 score classid
因为YOLOv10模型不需要NMS了,所以就直接输出最终得预测结果,支持默认最大得boxes数目是300, 这个应该是可以改得,我还没仔细研究,不然显然支持得预测框太少,这点跟YOLOv8预测框相比少了很多。模型转换代码如下:
from ultralytics import RTDETR, YOLO10
"""Test exporting the YOLO model to ONNX format."""
f = YOLO10("yolov10s.pt").export(format="onnx", dynamic=True)
单纯从推理上看 YOLOv10的确比YOLOv8简单很多,有点SSD模型得既视感。推理代码实现如下:
import cv2 as cv import numpy as np from openvino.runtime import Core # load model labels = load_classes() ie = Core() for device in ie.available_devices: print(device) model = ie.read_model(model="yolov10n.onnx") compiled_model = ie.compile_model(model=model, device_name="CPU") output_layer = compiled_model.output(0) frame = cv.imread("D:/images/1234.jpg") image = format_yolov10(frame) h, w, c = image.shape x_factor = w / 640.0 y_factor = h / 640.0 # 检测 2/255.0, NCHW = 1x3x640x640 blob = cv.dnn.blobFromImage(image, 1 / 255.0, (640, 640), swapRB=True, crop=False) # 设置网络输入 cvOut = compiled_model([blob])[output_layer] # [left,top, right, bottom, score, classId] print(cvOut.shape) for row in cvOut[0,:,:]: score = float(row[4]) objIndex = int(row[5]) if score > 0.5: left, top, right, bottom = row[0].item(), row[1].item(), row[2].item(), row[3].item() left = int(left * x_factor) top = int(top * y_factor) right = int(right * x_factor) bottom = int(bottom * y_factor) # 绘制 cv.rectangle(frame, (int(left), int(top)), (int(right), int(bottom)), (255, 0, 0), thickness=2) cv.putText(frame, "score:%.2f, %s"%(score, labels[objIndex]), (int(left) - 10, int(top) - 5), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2, 8); cv.imshow('YOLOv10 Object Detection', frame) cv.imwrite("D:/result.png", frame) cv.waitKey(0) cv.destroyAllWindows()
运行结果如下:
个人认为,这个就是一个YOLOv8的魔改版本,但是也是魔改界的天花板,还是不错的。然后下载它的源码之后,你会发现里面很多YOLOv8的包跟代码注释连名字都还没有改过来,特别是推理的演示代码里面还是YOLOv8的,说明是fork YOLOv8的代码基础上修改的,跟论文说明是一致的!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。