WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.21k stars 4.17k forks source link

(WongKinYiu / PyTorch_YOLOv4) Any talented one knows how to solve this error? RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu) #1502

Closed MheadHero closed 1 year ago

MheadHero commented 1 year ago

This is WongKinYiu / PyTorch_YOLOv4 problem. I found many solutions of this problem in YOLOv7, and no solution in YOLOv4. Since, the community here is more active. Thus, I try to ask here also. Hope any god can help with my problem.

Btw this is the link to WongKinYiu YOLOv4 loss.py

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)

dsbyprateekg commented 1 year ago

We have also faced the same issue while using PyTorch version and it was fixed for some weights as you can check below PR- https://github.com/WongKinYiu/yolov7/pull/1344

MheadHero commented 1 year ago

Ya, I have taken a look at it but both codes are quite different. Thats why need some talent to help us out.

dsbyprateekg commented 1 year ago

@MheadHero You can train your custom dataset with PyTorch_YOLOv7-tiny as well. Dataset format is same for both.

MheadHero commented 1 year ago

@MheadHero You can train your custom dataset with PyTorch_YOLOv7-tiny as well. Dataset format is same for both.

No, I need to use YOLOv4 to compare with other state of arts models in my thesis paper. Thats why, I need ask for help here.

dsbyprateekg commented 1 year ago

In that case, I suggest you use Darknet for training YOLOv4. The author has mentioned very good documentation in below link- https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

MheadHero commented 1 year ago

It's okay, Sir I will wait for someone to help with this issue. Because last time I have implemented YOLOv4 using wongkinyiu repo and has recorded their performance in my thesis already. Now what I need is trying to make the code working only. Thank you for the replies.

ekko-1996 commented 1 year ago

@MheadHero Maybe it can help you! https://github.com/WongKinYiu/PyTorch_YOLOv4/issues/296#issuecomment-1406707124

MheadHero commented 1 year ago

@MheadHero Maybe it can help you! WongKinYiu/PyTorch_YOLOv4#296 (comment)

Thank you! You are definitely a god!