YOLOV5 v 6.1 版本报错

/yolov5-pytorch/yolov5/utils/loss.py", line 217, in build_targets
    indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))  # image, anchor, grid indices
RuntimeError: result type Float can't be cast to the desired output type long int 

YOLOV5训练时遇到TuntimeError错误,问题出现在损失函数计算过程中。错误表明浮点数不能转换为长整型。解决方案是修改utils/loss.py文件中build_targets函数的两处代码,将特定索引的计算更改为考虑形状信息,避免类型不匹配。修复后的代码使得索引计算正确适应图像和网格的尺寸。  

解决方案:

修改utils文件夹下loss.py文件中class ComputeLoss类中def build_targets()函数:

        1、可能第184行,或是第167行:
源代码
anchors = self.anchors[i]

修改为 
anchors, shape = self.anchors[i],p[i].shape




注意:如果源码为:
anchors = det.anchors[i]

则修改为:
anchors, shape = det.anchors[i], p[i].shape

2. 可能是第218行,或是第200行:

源代码
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))  # image, anchor, grid indices

修改为:
indices.append((b,a,gj.clamp_(0,shape[2] - 1),gi.clamp_(0,shape[3] - 1)))  # image, anchor, grid indices

参考资料:YOLOV5报错:RuntimeError: result type Float can‘t be cast to the desired output type long int_file "train.py", line 627, in <module> main(opt)-CSDN博客

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值