如何解决这个错误? RuntimeError:索引应该位于 cpu 上或与索引张量 (cpu) 位于同一设备上

问题描述 投票:0回答:1

这是 WongKinYiu / PyTorch_YOLOv4 问题。我在YOLOv7中找到了很多这个问题的解决方案,在YOLOv4中没有找到解决方案。因为,这里的社区更加活跃。因此,我也尝试在这里问。

这是WongKinYiu loss.py的链接

Traceback (most recent call last):
File "/content/PyTorch_YOLOv4/train.py", line 537, in
train(hyp, opt, device, tb_writer, wandb)
File "/content/PyTorch_YOLOv4/train.py", line 288, in train
loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size
File "/content/PyTorch_YOLOv4/utils/loss.py", line 69, in compute_loss
tcls, tbox, indices, anchors = build_targets(p, targets, model) # targets
File "/content/PyTorch_YOLOv4/utils/loss.py", line 151, in build_targets
a, t = at[j], t.repeat(na, 1, 1)[j] # filter
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
python pytorch detection yolov4 yolov7
1个回答
0
投票

官网issue下已经有人提供了解决方案
在此输入链接描述

© www.soinside.com 2019 - 2024. All rights reserved.