open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.28k stars 9.41k forks source link

IndexError: list index out of range #3738

Closed sakurasakura1996 closed 4 years ago

sakurasakura1996 commented 4 years ago

Thank you for viewing my problem! This is my first experience using mmdetection.When I use it to train my custom dataset(num_classes = 7),I use cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py to train,and I modify num_classes=7 ,data_root. ann_file and img_prefix,and I meet this problem:

Traceback (most recent call last): File "train.py", line 175, in main() File "train.py", line 171, in main meta=meta) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/apis/train.py", line 143, in train_detector runner.run(data_loaders, cfg.workflow, cfg.total_epochs) File "/usr/local/lib/python3.6/dist-packages/mmcv/runner/epoch_based_runner.py", line 122, in run epoch_runner(data_loaders[i], kwargs) File "/usr/local/lib/python3.6/dist-packages/mmcv/runner/epoch_based_runner.py", line 46, in train self.call_hook('after_train_epoch') File "/usr/local/lib/python3.6/dist-packages/mmcv/runner/base_runner.py", line 298, in call_hook getattr(hook, fn_name)(self) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/core/evaluation/eval_hooks.py", line 75, in after_train_epoch self.evaluate(runner, results) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/core/evaluation/eval_hooks.py", line 79, in evaluate results, logger=runner.logger, self.eval_kwargs) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/datasets/coco.py", line 410, in evaluate result_files, tmp_dir = self.format_results(results, jsonfile_prefix) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/datasets/coco.py", line 355, in format_results result_files = self.results2json(results, jsonfile_prefix) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/datasets/coco.py", line 287, in results2json json_results = self._det2json(results) File "/content/drive/My Drive/mmdetection/mmdetection/mmdet/datasets/coco.py", line 224, in _det2json data['category_id'] = self.cat_ids[label] IndexError: list index out of range

I find some people also meet this problem, but I don't find true solution

sakurasakura1996 commented 4 years ago

My dataset has 7 classes,and I find the problem caused by code: self.cat_ids = self.coco.get_cat_ids(cat_names = self.CLASSES I print self.cat_ids, the answer is [0,1,2,3,4,5],it has only 6 classes,but I am sure the dataset has 7 classes and ann_file has 7 kind of labels

RyanXLi commented 4 years ago

Hi! When I try to reproduce this problem my self.cat_ids is [1, 2, 3, 4, 5, 6, 7]. Please make sure you have the right version of mmpycocotools first. You can Run pip uninstall pycocotools first. Then run pip install mmpycocotools to install open-mmlab forked pycocotools.

sakurasakura1996 commented 4 years ago

Hi! When I try to reproduce this problem my self.cat_ids is [1, 2, 3, 4, 5, 6, 7]. Please make sure you have the right version of mmpycocotools first. You can Run pip uninstall pycocotools first. Then run pip install mmpycocotools to install open-mmlab forked pycocotools.

Thank you,I try it with: !pip uninstall pycocotools !pip install mmcv-full==1.1.1+torch1.6.0+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html !pip install -r requirements/build.txt !pip install -U "git+https://github.com/open-mmlab/cocoapi.git#subdirectory=pycocotools" !python setup.py develop but it still not works! is my installation wrong?

ShihuaiXu commented 3 years ago

Sir, have you solved this problem?