dbolya / yolact

A simple, fully convolutional model for real-time instance segmentation.
MIT License
5.03k stars 1.32k forks source link

Index out of range for Yolact model.. #797

Open Mayuresh999 opened 1 year ago

Mayuresh999 commented 1 year ago

I got this error while training on a custom dataset... I've already done changing necessary things in config.py what is the solution for this?

firstly i've change the dataset to this:- Pothole_dataset = dataset_base.copy({ 'name': 'Pothole_dataset', 'train_info': '/content/drive/MyDrive/Road_potholes/train/_annotations.coco.json', 'train_images': '/content/drive/MyDrive/Road_potholes/train/', 'valid_info': '/content/drive/MyDrive/Road_potholes/valid/_annotations.coco.json', 'valid_images': '/content/drive/MyDrive/Road_potholes/valid/', 'class_names': ('Pothole',), 'label_map': { 1: 1 } })

then in config: yolact_resnet50_potholes_config = yolact_resnet50_config.copy({ 'name': 'yolact_plus_resnet50_potholes',

Dataset stuff

'dataset': Pothole_dataset,
'num_classes': len(Pothole_dataset.class_names) + 1,
# Image Size
'max_size': 300,

})

please help @dbolya

Error-----

/content/yolact loading annotations into memory... Done (t=0.01s) creating index... index created! loading annotations into memory... Done (t=0.00s) creating index... index created! Initializing weights... Begin training!

Traceback (most recent call last): File "./train.py", line 504, in train() File "./train.py", line 270, in train for datum in data_loader: File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 345, in next data = self._next_data() File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 856, in _next_data return self._process_data(data) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 881, in _process_data data.reraise() File "/usr/local/lib/python3.7/dist-packages/torch/_utils.py", line 394, in reraise raise self.exc_type(msg) IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/content/yolact/data/coco.py", line 94, in getitem im, gt, masks, h, w, num_crowds = self.pull_item(index) File "/content/yolact/data/coco.py", line 148, in pull_item masks = [self.coco.annToMask(obj).reshape(-1) for obj in target] File "/content/yolact/data/coco.py", line 148, in masks = [self.coco.annToMask(obj).reshape(-1) for obj in target] File "/usr/local/lib/python3.7/dist-packages/pycocotools/coco.py", line 442, in annToMask rle = self.annToRLE(ann) File "/usr/local/lib/python3.7/dist-packages/pycocotools/coco.py", line 427, in annToRLE rles = maskUtils.frPyObjects(segm, h, w) File "pycocotools/_mask.pyx", line 293, in pycocotools._mask.frPyObjects IndexError: list index out of range

bhushangawde commented 1 year ago

Hey @Mayuresh999 Did you find the solution? I am stuck with the same issue. Please help

alessio76 commented 1 year ago

I've experienced the same issue and in my case the bug was in the json annotation file, in particular some segmentation sublist was empty. Actually, looking at https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/_mask.pyx#:~:text=def%20frPyObjects(pyobj%2C%20h%2C%20w) you can see that you must set at least four elements (therefore 2 points) in each sublist of the segmentation field. Check the link to see the complete list of cases which throw that exception.

bhushangawde commented 1 year ago

I was able to fix it by fixing the annotation file. My file had a few empty lists in segmentation which led to this issue. Removing them helped it to run successfully.