yoloair icon indicating copy to clipboard operation
yoloair copied to clipboard

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

Open AKA-WDNMD opened this issue 2 years ago • 0 comments

Describe the bug RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

To Reproduce Steps to reproduce the behavior: 1.运行python train.py --img 640 --batch 4 --epochs 50 --data coco.yaml --weights yolov5s.pt --device '0'

ecfa0b573078b0cda62bcc5b8c4a085

解决方法:

  1. ./utils/loss.py的685行改为 :from_which_layer.append((torch.ones(size=(len(b),)) * i).to('cuda'))
  2. ./utils/loss.py的756行之后添加多一行:fg_mask_inboxes = fg_mask_inboxes.to(torch.device('cuda'))
    参考:https://stackoverflow.com/questions/74372636/indices-should-be-either-on-cpu-or-on-the-same-device-as-the-indexed-tensor

AKA-WDNMD avatar Jan 09 '23 03:01 AKA-WDNMD