在用yolov8做数据训练自己的数据时发现,这样一个错误,困扰了我很久。报错的原因是数组的问题,我查了一下百度,说是定义数组的问题,之后我就慌的一批,这个源包这么多,该去哪排查。
raceback (most recent call last):
File "d:\jiaotong\ultralytics-8.1.0\my train.py", line 10, in <module>
results = model.train(data='yolo-bvn.yaml', epochs=20, imgsz=640)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\engine\model.py", line 390, in train
self.trainer.train()
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\engine\trainer.py", line 208, in train
self._do_train(world_size)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\engine\trainer.py", line 379, in _do_train
self.loss, self.loss_items = self.model(batch)
File "C:\Users\15200\.conda\envs\ultralytics\lib\site-packages\torch\nn\modules\module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "C:\Users\15200\.conda\envs\ultralytics\lib\site-packages\torch\nn\modules\module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\nn\tasks.py", line 79, in forward
return self.loss(x, *args, **kwargs)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\nn\tasks.py", line 258, in loss
return self.criterion(preds, batch)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\utils\loss.py", line 220, in __call__
_, target_bboxes, target_scores, fg_mask, _ = self.assigner(
File "C:\Users\15200\.conda\envs\ultralytics\lib\site-packages\torch\nn\modules\module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "C:\Users\15200\.conda\envs\ultralytics\lib\site-packages\torch\nn\modules\module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\15200\.conda\envs\ultralytics\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\utils\tal.py", line 72, in forward
mask_pos, align_metric, overlaps = self.get_pos_mask(
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\utils\tal.py", line 94, in get_pos_mask
align_metric, overlaps = self.get_box_metrics(pd_scores, pd_bboxes, gt_labels, gt_bboxes, mask_in_gts * mask_gt)
File "d:\jiaotong\ultralytics-8.1.0\ultralytics\utils\tal.py", line 113, in get_box_metrics
bbox_scores[mask_gt] = pd_scores[ind[0], :, ind[1]][mask_gt] # b, max_num_obj, h*w
IndexError: index 17 is out of bounds for dimension 1 with size 17
经过排查,终于找到了,一个十分低级的错误,我在修改的coco8.yaml文件时,待识别的类个数少了一个。这个是我们在使用labelimg时,标注图片类的个数,一一对应打上去。这两个要一摸一样。
之后在运行代码,进行训练就可以,下一期会出一个完整版的使用yolov8进行训练自己的数据集。
标签:8.1,index,py,IndexError,17,self,ultralytics,File,line From: https://blog.csdn.net/weixin_60819517/article/details/139915123