使用Yolov5进行模型训练的时候,出现了error:
RuntimeError: result type Float can‘t be cast to the desired output type long int
数据集完成了加载,并且没有出现其他问题,但是却报错
报错的原因是:
loss计算过程中,出现Float的数值精度,需要进行精度的强转换。
解决方法:
修改【utils】中的【loss.py】里面的两处内容
第一处代码修改:
anchors, shape = self.anchors[i], p[i].shape
第二处代码修改:
indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, grid
目的是将两种类型的shape进行拉齐。
代码修改通过,模型顺利跑通过。