在博客上下载了一套源码学习,这个用yolov5的官方权重训练Coco数据集得到的新权重可以用,但是换成自己的数据集,在detect里面可以用,但是放到那个qt界面里就不行了
你可以尝试使用OpenCV来可视化yolov5的检测结果。具体步骤如下:
results = model(img)
predictions = non_max_suppression(results, conf_thres=0.4, iou_thres=0.5)
detections = []
for pred in predictions:
if pred is not None and len(pred) > 0:
detections.extend(pred.cpu().numpy())
import cv2
img = cv2.imread('<path_to_image>')
for detection in detections:
x1, y1, x2, y2, conf, cls = detection
cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 0, 255), 2)
cv2.putText(img, str(cls.numpy()), (int(x1), int(y1)-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
cv2.imshow('Detection', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
希望这个思路对你有帮助。