解决yoloV7报错:indices should be either on cpu or on the same device as the indexed tensor (cpu)

文章指导如何在loss.py文件中针对CUDA和CPU设备进行适当调整,包括修改torch.device的使用、将ones转换为相应设备的tensor以及确保matching_matrix初始化使用设备。
摘要由CSDN通过智能技术生成

step1 在loss.py文件导包后添加

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

step2  添加to(device)

修改:from_which_layer.append(torch.ones(size=(len(b),)) * i)
修改为:from_which_layer.append((torch.ones(size=(len(b),)) * i).to(device))

备注:loss.py文件中有多处,每处都需要修改

step2  添加device=device

修改:matching_matrix = torch.zeros_like(cost)
修改为:matching_matrix = torch.zeros_like(cost, device=device)

备注:loss.py文件中有多处,每处都需要修改

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值