使用YOLOv5-6.1训练数据集遇到的问题及解决方法
问题1:使用GPU进行训练时,报错IndexError: index 3 is out of bounds for dimension 1 with size 3
报错位置是在loss.py的class ComputeLoss: 中
t[range(n), tcls[i]] = self.cp
解决方法:
- 首先检测类别数目的设置,如果数据集中的类别数目为3,则VOC.yaml文件中的nc应设置为3.
- 检测标注的txt文件中,是否有标注错误,例如你自己标注的类的label为0、1、2,需要检查是否有label为3,或者其他的值。
问题2:报错result type float can‘t be cast to the desired output type long int
在loss.py文件下修改
gain = torch.ones(7, device = device)
替换为
gain = torch.ones(7, device = device).long()
这个问题是参考了这篇博客:博客链接