WongKinYiu / PyTorch_YOLOv4

PyTorch implementation of YOLOv4
1.86k stars 585 forks source link

RuntimeError: result type Float can't be cast to the desired output type __int64 #416

Closed Jedrekcangxin closed 1 year ago

Jedrekcangxin commented 1 year ago

Traceback (most recent call last): File "train.py", line 537, in train(hyp, opt, device, tb_writer, wandb) File "train.py", line 288, in train loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size File "E:\yolo_test\yolo\code\yolov4-master\utils\loss.py", line 66, in compute_loss tcls, tbox, indices, anchors = build_targets(p, targets, model) # targets File "E:\yolo_test\yolo\code\yolov4-master\utils\loss.py", line 167, in buildtargets indices.append((b, a, gj.clamp(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices RuntimeError: result type Float can't be cast to the desired output type __int64

foemre commented 1 year ago

Downgrade your torch version to 1.7.0. pip install torch==1.7.0 https://github.com/ultralytics/yolov5/issues/8405

Tefor commented 1 year ago

In loss.py (line 173 ), gain = torch.ones(7, device=targets.device) gain = torch.ones(7, device=targets.device).int()

Jedrekcangxin commented 1 year ago

In loss.py (line 138) add: “shape = p[i].shape” (line 186) change: indices.append((b, a, gj.clamp(0, gain[3] - 1), gi.clamp(0, gain[2] - 1))) → indices.append((b, a, gj.clamp(0, shape[2] - 1), gi.clamp(0, shape[3] - 1)))

the issue solved