WongKinYiu / PyTorch_YOLOv4

PyTorch implementation of YOLOv4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

MheadHero opened this issue · comments

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)

i met same problem

i met same problem

lets try find some expert to help us out!

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.

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

commented

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

commented

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