open-mmlab / mmdetection

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

CocoDataset returns error no "ann_info" key when test_mode =True, It's ok when test_mode= False #5351

Closed fangxu622 closed 3 years ago

fangxu622 commented 3 years ago

Describe the bug CocoDataset returns error no "ann_info" key when test_mode =True, It's ok when test_mode= False

Code image

Environment pytorch 1.81,mmcv 1.3.5 ,mmdet 2.13

Error traceback

(base) root@060a3ecd3832:/workspace# /opt/conda/bin/python /workspace/mmdett/tests/test_transform.py
loading annotations into memory...
Done (t=0.04s)
creating index...
index created!
Traceback (most recent call last):
  File "/workspace/mmdett/tests/test_transform.py", line 170, in <module>
    test2_mosaic(1)
  File "/workspace/mmdett/tests/test_transform.py", line 101, in test2_mosaic
    results = mc_dataset.__getitem__(7)
  File "/workspace/mmdetection/mmdet/datasets/custom.py", line 192, in __getitem__
    return self.prepare_test_img(idx)
  File "/workspace/mmdetection/mmdet/datasets/custom.py", line 235, in prepare_test_img
    return self.pipeline(results)
  File "/workspace/mmdetection/mmdet/datasets/pipelines/compose.py", line 40, in __call__
    data = t(data)
  File "/workspace/mmdetection/mmdet/datasets/pipelines/loading.py", line 365, in __call__
    results = self._load_bboxes(results)
  File "/workspace/mmdetection/mmdet/datasets/pipelines/loading.py", line 240, in _load_bboxes
    ann_info = results['ann_info']
KeyError: 'ann_info'
hhaAndroid commented 3 years ago

Hi @fangxu622 This is because test_mode =True represents the test mode, it will ignore the label directly.

if self.test_mode:
     return self.prepare_test_img(idx)

def prepare_test_img(self, idx):
    """Get testing data  after pipeline.
    Args:
        idx (int): Index of data.
    Returns:
        dict: Testing data after pipeline with new keys introduced by \
            pipeline.
    """
    img_info = self.data_infos[idx]
    results = dict(img_info=img_info)
    if self.proposals is not None:
        results['proposals'] = self.proposals[idx]
    self.pre_pipeline(results)
    return self.pipeline(results)

This is normal. What requirements are you trying to achieve?