YOLOv5:按每个类别的不同置信度阈值输出预测框

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

前言

前提条件

相关介绍

  • Python是一种跨平台的计算机程序设计语言。是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越多被用于独立的、大型项目的开发。
  • PyTorch 是一个深度学习框架,封装好了很多网络和深度学习相关的工具方便我们调用,而不用我们一个个去单独写了。它分为 CPU 和 GPU 版本,其他框架还有 TensorFlow、Caffe 等。PyTorch 是由 Facebook 人工智能研究院(FAIR)基于 Torch 推出的,它是一个基于 Python 的可续计算包,提供两个高级功能:1、具有强大的 GPU 加速的张量计算(如 NumPy);2、构建深度神经网络时的自动微分机制。
  • YOLOv5是一种单阶段目标检测算法,该算法在YOLOv4的基础上添加了一些新的改进思路,使其速度与精度都得到了极大的性能提升。它是一个在COCO数据集上预训练的物体检测架构和模型系列,代表了Ultralytics对未来视觉AI方法的开源研究,其中包含了经过数千小时的研究和开发而形成的经验教训和最佳实践。

YOLOv5:按每个类别的不同置信度阈值输出预测框

在这里插入图片描述

预测

在这里插入图片描述

修改detect.py

				# filter with label, class, map
                filter_score_maps = {
                    0 : 0.45, # person
                    5 : 0.85, # bus
                }

                # Write results
                for *xyxy, conf, cls in reversed(det):
                    # filter with label, class # 按照各个类别框的置信度,过滤框
                    if int(cls) in filter_score_maps.keys() and conf < filter_score_maps[int(cls)]:
                        continue
                    if save_txt:  # Write to file
                        xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
                        line = (cls, *xywh, conf) if save_conf else (cls, *xywh)  # label format
                        with open(txt_path + '.txt', 'a') as f:
                            f.write(('%g ' * len(line)).rstrip() % line + '\n')

                    if save_img or save_crop or view_img:  # Add bbox to image
                        c = int(cls)  # integer class
                        label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')
                        annotator.box_label(xyxy, label, color=colors(c, True))
                        if save_crop:
                            save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

在这里插入图片描述

输出结果

在这里插入图片描述

验证

在这里插入图片描述

修改val.py

            # filter with label, class, map
            filter_score_maps = {
                0 : 0.45, # person
                5 : 0.85, # bus
            }

            # Write results
            filter_pred = []
            for i,(*xyxy, conf, cls) in enumerate(pred):
                # filter with label, class # 按照各个类别框的置信度,过滤框
                # print((i,conf, cls))
                if (int(cls) not in filter_score_maps.keys()) or (int(cls) in filter_score_maps.keys() and conf > filter_score_maps[int(cls)]):
                    filter_pred.append(pred[i].tolist())
                
            pred = torch.Tensor(filter_pred).to(device)

在这里插入图片描述

输出结果

在这里插入图片描述

参考

[1] https://github.com/ultralytics/yolov5.git

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FriendshipT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值