#542·yolov10

导出模型为 onnx 时检测结果发生偏移

作者: nguyenthaohut创建于 2025年7月12日更新于 2025年9月27日

我试图使用 opencv 将模型转换为 onnx 以进行部署,在 pt 权重中它可以检测到,但将其转换为 onnx 后,检测结果发生了偏移。这是我在尝试检测树形大小免费软件的主按钮和选择文件夹按钮时的检测结果。[url=https://anh.moe/view/f8KTwx]https://anh.moe/view/f8KTwx[/url] `from ultralytics import YOLOv10 import cv2 import glob import os model_path = "runs_1/detect/train/weights/best.onnx" video_path = "Image" save_video_path = "output/output.avi" model = YOLOv10(model_path) label = ["Home", "Select"] video = True image = False path = glob.glob(video_path) for p in path: for filename in os.listdir(p): full_path = os.path.join(p, filename) print(full_path) if filename.__contains__("jpg"): model.predict(full_path, save=True, conf=0.5) frame_Full = cv2.imread(full_path) frame = cv2.resize(frame_Full, (640, 640)) frame_cp = frame.copy() # frame_cp = frame_cp[224:868, 520:1140] w = 640 h=640 results = model(source=frame_cp, conf=0.1) for r in results: if r.boxes is None: print('None') continue for result in r.boxes.data: result = result.cpu().detach().numpy() boxes = result[:4] print(boxes) x, y, bw, bh = boxes left = int((x+13)*1920/640) top = int(y*1080/640) right = int((x+bw/2)*1920/640) bottom = int((y+bh/2)*1080/640) print('left, top, right, bottom') print(filename) print(left, top, right, bottom) #left, top, right, bottom = boxes classes = int(result[5]) scores = result[4] cv2.rectangle(frame_Full, (int(left), int(top)), (int(right), int(bottom)), color=[255, 255, 0], thickness=2) cv2.putText(frame_Full, f"{label[classes]}" + "_{:.2f}%".format(scores*100), (int(left), int(top)), cv2.FONT_HERSHEY_SIMPLEX, 1, color=[255, 255, 0], thickness=2) # cv2.imwrite((p[:-4]+'_org.jpg'), frame) cv2.imwrite("Test/"+filename, frame_Full)

内容来源: THU-MIG/yolov10