edgeai-yolov5 icon indicating copy to clipboard operation
edgeai-yolov5 copied to clipboard

Cannot training after loaded COCO dataset

Open nguyenanhtuan1008 opened this issue 2 years ago • 1 comments

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?

nguyenanhtuan1008 avatar Aug 25 '22 06:08 nguyenanhtuan1008

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

K-tang-mkv avatar Jun 07 '23 01:06 K-tang-mkv