【问题标题】:How to set and get confidence threshold from custom YOLOv5 model?如何从自定义 YOLOv5 模型中设置和获取置信度阈值?
【发布时间】:2021-07-20 15:07:53
【问题描述】:

我正在尝试对我的自定义 YOLOv5 模型进行推理。 official documentation 使用默认的 detect.py 脚本进行推理。

例如:python detect.py --source data/images --weights yolov5s.pt --conf 0.25

我已经编写了自己的 python 脚本,但我既不能在初始化期间设置置信度阈值,也不能从模型的预测中检索它。我只能获得标签和边界框坐标。这是我的代码:

import torch

model = torch.hub.load('ultralytics/yolov5', 'custom', path_or_model='best.pt') 
results = model("my_image.png")
labels, cord_thres = results.xyxyn[0][:, -1].numpy(), results.xyxyn[0][:, :-1].numpy()

【问题讨论】:

    标签: python pytorch inference yolov5


    【解决方案1】:

    它对我有用:

    model.conf = 0.25  # confidence threshold (0-1)
    model.iou = 0.45  # NMS IoU threshold (0-1)  
    

    更多信息:

    https://github.com/ultralytics/yolov5/issues/36

    【讨论】:

      【解决方案2】:

      查看detection.y 文件以获取有关使用该模型的明确说明。您必须在代码中的模型推断之后手动进行分数阈值处理。

      这意味着检测分数在 0.0 到 1.0 之间,您必须使用置信度阈值对其进行过滤。

      【讨论】:

        猜你喜欢
        • 2019-03-10
        • 2021-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多