microsoft / SoftTeacher

Semi-Supervised Learning, Object Detection, ICCV2021
MIT License
899 stars 123 forks source link

Traning on coco2014 got KeyError: 'categories' #171

Open zhiweil20 opened 2 years ago

zhiweil20 commented 2 years ago

I just wanna train on coco2014 and I got the error like below:

And I have modified the config file ann_file="data/coco/annotations/instances_train2014.json"

Traceback (most recent call last):
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/custom.py", line 95, in __init__
    self.data_infos = self.load_annotations(local_path)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/coco.py", line 75, in load_annotations
    self.cat_ids = self.coco.get_cat_ids(cat_names=self.CLASSES)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/api_wrappers/coco_api.py", line 31, in get_cat_ids
    return self.getCatIds(cat_names, sup_names, cat_ids)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/pycocotools/coco.py", line 192, in getCatIds
    cats = self.dataset['categories']
KeyError: 'categories'
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/ecnu-lzw/lzw/SoftTeacher/ssod/datasets/dataset_wrappers.py", line 9, in __init__
    super().__init__([build_dataset(sup), build_dataset(unsup)], **kwargs)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/builder.py", line 81, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: "CocoDataset: 'categories'"
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/train.py", line 198, in <module>
    main()
  File "tools/train.py", line 173, in main
    datasets = [build_dataset(cfg.data.train)]
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/builder.py", line 81, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: 'SemiDataset: "CocoDataset: \'categories\'"'
Traceback (most recent call last):
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/custom.py", line 95, in __init__
    self.data_infos = self.load_annotations(local_path)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/coco.py", line 75, in load_annotations
    self.cat_ids = self.coco.get_cat_ids(cat_names=self.CLASSES)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/api_wrappers/coco_api.py", line 31, in get_cat_ids
    return self.getCatIds(cat_names, sup_names, cat_ids)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/pycocotools/coco.py", line 192, in getCatIds
    cats = self.dataset['categories']
KeyError: 'categories'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/ecnu-lzw/lzw/SoftTeacher/ssod/datasets/dataset_wrappers.py", line 9, in __init__
    super().__init__([build_dataset(sup), build_dataset(unsup)], **kwargs)
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/builder.py", line 81, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: "CocoDataset: 'categories'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/train.py", line 198, in <module>
    main()
  File "tools/train.py", line 173, in main
    datasets = [build_dataset(cfg.data.train)]
  File "/home/ecnu-lzw/lzw/SoftTeacher/thirdparty/mmdetection/mmdet/datasets/builder.py", line 81, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/ecnu-lzw/miniconda3/envs/SoftTeacher/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: 'SemiDataset: "CocoDataset: \'categories\'"'

I have referred the issue 105

But I check the annotation file, and categories is exact a key there.

What's wrong with my problem?

Thank you for your help!

zhiweil20 commented 2 years ago

Sorry, I just check my unlabeled2017.json file, "categories" is really not there. Is this maybe cause the problem?

yuan738 commented 2 years ago

Hi, sorry for bothering. I had the same error, have you solved it? thank you~

zhiweil20 commented 2 years ago

@yuan738

Hi, sorry for bothering. I had the same error, have you solved it? thank you~

Hi, just as I mentioned before, there is not a "categories" in my unlabeled2017.json file, I modify my annotation file and add this attribute. The problem is solved. You can have a try.

yuan738 commented 2 years ago

thank you for your help! I will try it.