RuntimeError: result type Float can't be cast to the desired output type __int64
Jedrekcangxin opened this issue · comments
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 build_targets
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
Downgrade your torch version to 1.7.0.
pip install torch==1.7.0
ultralytics/yolov5#8405
In loss.py (line 173 ), gain = torch.ones(7, device=targets.device) → gain = torch.ones(7, device=targets.device).int()
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