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

How to solve this error? RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu) #424

Open
MheadHero opened this issue Feb 16, 2023 · 9 comments

Comments

@MheadHero
Copy link

MheadHero commented Feb 16, 2023

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)

@nanhai78
Copy link

i met same problem

@MheadHero
Copy link
Author

i met same problem

lets try find some expert to help us out!

@MheadHero
Copy link
Author

I have found a solution.
Modify your loss.py

add at = at.to(targets.device) above a, t = at[j], t.repeat(na, 1, 1)[j] # filter

Then,

uncomment indices.append((b, a, gj, gi)) # image, anchor, grid indices
comment indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices

This may solve the problem. Thank you.

@nanhai78
Copy link

I have found a solution. Modify your loss.py

add at = at.to(targets.device) above a, t = at[j], t.repeat(na, 1, 1)[j] # filter

Then,

uncomment indices.append((b, a, gj, gi)) # image, anchor, grid indices comment indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices

This may solve the problem. Thank you.
thank you very much

@lyl-9
Copy link

lyl-9 commented Apr 22, 2023

Hi, could you please provide the pre-training weights for YOLOv4pacsp-x-mish? Thank you very much! @nanhai78 @MheadHero

@nanhai78
Copy link

nanhai78 commented Apr 22, 2023 via email

@lyl-9
Copy link

lyl-9 commented Apr 22, 2023

Do you have the pre-training weight of voc? @nanhai78

@Qilingwan
Copy link

I have found a solution. Modify your loss.py

add at = at.to(targets.device) above a, t = at[j], t.repeat(na, 1, 1)[j] # filter

Then,

uncomment indices.append((b, a, gj, gi)) # image, anchor, grid indices comment indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices

This may solve the problem. Thank you.

Thx a lot.

@dhhdjsmsl
Copy link

thx very much

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

5 participants