Open zjh-acc opened 1 year ago
我也是,请问是什么问题?
我也是,求教啊......
import torch import numpy as np import cv2 from models.experimental import attempt_load from utils.datasets import letterbox from utils.general import non_max_suppression, scale_coords from utils.torch_utils import select_device
from ultralytics import YOLO
class Detector:
def __init__(self):
self.threshold=0.3
self.weights = r'/yolov5m.pt'
model = YOLO(
r'/yolov8s.pt') # 你可以选择不同的模型,例如 'yolov8s.pt', 'yolov8m.pt', 'yolov8l.pt', 'yolov8x.pt'
self.m = model
self.names = model.names
def detect(self, im):
results = self.m(im) # Perform detection
boxes = []
for result in results:
detections = result.boxes # 获取检测框信息
for det in detections:
# 获取检测框的坐标、置信度和类别
x1, y1, x2, y2 = det.xyxy[0].int().tolist() # 转换为整数坐标
conf = det.conf[0].item() # 获取置信度
cls = int(det.cls[0].item()) # 获取类别索引
if conf < self.threshold:
continue
label = self.names[cls]
if label not in ['person', 'bicycle', 'car', 'motorcycle', 'bus', 'truck']:
continue
boxes.append((int(x1), int(y1), int(x2), int(y2), label, conf))
return boxes
detector检测脚本有问题,替换为yolov8ba