目标检测-YOLOv4训练报错问题(RuntimeError: indices should be either on cpu or on the same device as the indexe)

首先定位到报错的位置

File "/home/zhangh/project1/pytorch-YOLOv4-master/PyTorch_YOLOv4-master/PyTorch_YOLOv4-master/utils/loss.py", line 148

通过

            print("------------------------------------------------------------------------")
            print(f"at device: {at.device}")
            print(f"j device: {j.device}")

            print(f"t device: {t.device}")

输出得知

at device居然在CPU上,然后用

at = torch.arange(na).view(na, 1).repeat(1, nt).to(torch.device(device))

把 at转移到GPU上,然后再运行

居然再次报错,不过好在不是同一个地方报错

分析可知此处报错是因为数据类型报错,然后查博客得知:原因:新版本的torch无法自动执行转换操作,而旧版本可以。本文中报错版本为torch 1.13.1, torchaudio 0.13.1, torchvision 0.14.1。(博客链接如下)

【纠错】RuntimeError: result type Float can’t be cast to the desired output type long int_runtimeerror: result type float can't be cast to t-CSDN博客

此处博客有个问题,转换数据类型应该是

 gain[2].to(torch.long)

完整修正如下: 

indices.append((b, a, gj.clamp_(0, gain[3].to(torch.long) - 1), gi.clamp_(0, gain[2].to(torch.long) - 1)))  # image, anchor, grid indices

自此就大功告成

 

完美开始训练

奈斯~~~ 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值