更改yolo结果文本内容

关于yolov5的教程,讲解如何在detect.py中修改代码以在检测结果中添加良好标签,关注输出内容和annoator.box_label函数的更新。
摘要由CSDN通过智能技术生成

本文是基于训练好的yolov5模型进行更改,即更改detect.py中的代码

信息储存位置

改变输出内容,我们就要找到结果生成的代码。阅读代码,找到 251 行
(# Write results ) 为结果生成代码。

# Write results  
for *xyxy, conf, cls in reversed(det):  

    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)  # labelformat  
        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)

不难看出,annoator.box_lable为相关函数。label储存了文本信息

更改代码

更改:

label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')

即可
如加入‘良好’

label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f} {'良好'}')

参考: yolov5——detect.py代码【注释、详解、使用教程】-CSDN博客

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值