Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AKA-WDNMD opened this issue Jan 9, 2023 · 0 comments

Comments

@AKA-WDNMD
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant