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) #1101
Comments
https://github.com/WongKinYiu/yolov7/blob/main/utils/loss.py#L742 Changing this line to
worked for me. |
|
I am wandering, even if we dont mention device="cpu" explicitly, its gets created in cpu only right ? |
I think |
If you're training
in the same file ( |
Great, that worked for me! |
This is occurring due to device issue. I run the same code on colab it worked perfectly fine. But when I tried using AWS it was giving this error. The above answer worked for me. Thanks. |
when i used the command python train.py --workers 8 --device 0 --batch-size 16 --data data.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights yolov7x.pt --name yolov7 --hyp data/hyp.scratch.p5.yaml I got this error RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu) I modified the loss.py file to automatically get the index of the default GPU selected using torch.device('cuda') function fixes WongKinYiu#1225 WongKinYiu#1224 WongKinYiu#1101 WongKinYiu#1045
|
matching_matrix = torch.zeros_like(cost, device="cuda") at line 742 in loss.py worked for me |
wasn't working, but
did, probably because I had already modified a couple lines in |
I spent 3-4 hours trying other methods, and in the end, I successfully ran YOLO7 training w6 on August 6, 2023. Thank you |
I feel you. Would really appreciate, if it would get fixed. Thank you! :) @WongKinYiu |
indices should be either on cpu or on the same device as the indexed tensor (cpu) WongKinYiu#1101
Traceback (most recent call last):
File "/home/arnav/Sushovan/yolov7-main/train.py", line 622, in
train(hyp, opt, device, tb_writer)
File "/home/arnav/Sushovan/yolov7-main/train.py", line 369, in train
loss, loss_items = compute_loss_ota(pred, targets, imgs) # loss scaled by batch_size changed
File "/home/arnav/Sushovan/yolov7-main/utils/loss.py", line 585, in call
bs, as_, gjs, gis, targets, anchors = self.build_targets(p, targets, imgs)
File "/home/arnav/Sushovan/yolov7-main/utils/loss.py", line 759, in build_targets
from_which_layer = from_which_layer[fg_mask_inboxes]
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
Please help in solving the error. Do I need to transfer some part of code to gpu ? Then which part ?
Actually, it was working fine in simple GPU, but showing this error in HPC.
The text was updated successfully, but these errors were encountered: