JiayuanWang-JW / YOLOv8-multi-task

GNU Affero General Public License v3.0
227 stars 38 forks source link

IndexError upon modifying the model for multi-class detection #13

Open eddyminer opened 10 months ago

eddyminer commented 10 months ago

Sorry for troubling you again. I tried to modify the single class detection to multi-class detection instead. However an error was encountered as below. I afraid any of my changes will affect the whole training process. Can you help up with this?

Starting training for 1 epochs...

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss    Tv_loss    FL_loss    Tv_loss    FL_loss  Instances       Size

0%| | 0/5834 [00:00<?, ?it/s]torch.Size([12, 46]) torch.Size([12, 46]) torch.Size([12, 46, 8400]) torch.Size([12, 8400, 4]) 0%| | 0/5834 [00:04<?, ?it/s] Traceback (most recent call last): File "train.py", line 12, in model.train(data='/home/user/Desktop/many_class/ultralytics/datasets/bdd-multi.yaml', batch=12, epochs=1, imgsz=(640,640), name='yolopm', val=True, task='multi',classes=[2,3,4,9,10,11]) File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/engine/model.py", line 387, in train self.trainer.train() File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/engine/trainer.py", line 195, in train self._do_train(world_size) File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/engine/trainer.py", line 366, in _do_train self.mul_loss[count], self.mul_loss_items[count] = self.criterion(preds[count], batch[count], self.data['labels_list'][count],count) File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/v8/DecSeg/train.py", line 114, in criterion return self.computeloss(preds, batch) File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/v8/DecSeg/train.py", line 268, in call , target_bboxes, target_scores, fgmask, = self.assigner( File "/home/user/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl return forward_call(*input, *kwargs) File "/home/user/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(args, *kwargs) File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/utils/tal.py", line 112, in forward mask_pos, align_metric, overlaps = self.get_pos_mask(pd_scores, pd_bboxes, gt_labels, gt_bboxes, anc_points, File "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/utils/tal.py", line 133, 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 "/home/user/.local/lib/python3.8/site-packages/ultralytics/yolo/utils/tal.py", line 153, in get_box_metrics bbox_scores[mask_gt] = pd_scores[ind[0], :, ind[1]][mask_gt] # b, max_num_obj, h*w IndexError: index 4 is out of bounds for dimension 1 with size 4

Edited: I realise a problem where if two detection heads are created for this model, both the detection heads can only detect the same thing, i.e. same types and number of objects. Any idea to solve this?

liu-haoyu commented 6 months ago

I have encountered the same problem. May I ask if you have resolved this issue? I hope to receive some guidance from you. Thank you very much

PotatoNU commented 6 months ago

I'm also running into this issue, please how can I fix it

LiuJinchao000 commented 4 months ago

I'm also running into this issue, please how can I fix it

kokun66 commented 1 month ago

Anybody made it?