edgeai-yolov5
edgeai-yolov5 copied to clipboard
Cannot training after loaded COCO dataset
I got the error during training COCO dataset.
Exception has occurred: RuntimeError
result type Float can't be cast to the desired output type __int64
File "F:\edgeai-yolov5\utils\loss.py", line 236, in build_targets
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices
File "F:\edgeai-yolov5\utils\loss.py", line 120, in __call__
tcls, tbox, tkpt, indices, anchors = self.build_targets(p, targets) # targets
File "F:\edgeai-yolov5\train_custom.py", line 306, in train
loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size
File "F:\edgeai-yolov5\train_custom.py", line 550, in <module>
train(hyp, opt, device, tb_writer)
How to fix this issue?
In this error and the piece of code, gain
is float type tensor, and your torch version is actually unable to cast it to long int type. So there are two ways to solve this error, one is using torch version=1.7, that can make it, and the second way is change the code like this
gain_cp = gain.long()
indices.append((b, a, gj.clamp_(0, gain_cp[3] - 1), gi.clamp_(0, gain_cp[2] - 1))) # image, anchor, grid indices