Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行无报错,但是没有检测框和数量变化,求教是什么问题? #44

Open
zjh-acc opened this issue Feb 28, 2023 · 3 comments

Comments

@zjh-acc
Copy link

zjh-acc commented Feb 28, 2023

image

@LSJ5106
Copy link

LSJ5106 commented Mar 3, 2023

我也是,请问是什么问题?

@jaybryant1
Copy link

我也是,求教啊......

@Bob-jpg
Copy link

Bob-jpg commented Sep 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants