Skip to content

Conversation

@carandraug
Copy link
Contributor

The COCO.loadRes returns a new COCO object with the results. It does this by copying the images and categories fields from the COCO data object. However, it does not copy the info dict. The end result is that the info() method in the returned results COCO fails:

>>> coco_res = coco_data.loadRes(...)
>>> coco_res.info()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/site-packages/pycocotools/coco.py", line 124, in info
    for key, value in self.dataset['info'].items():
                      ~~~~~~~~~~~~^^^^^^^^
KeyError: 'info'

ThIs PR copies the original info field so things work. I'm not sure if it is the best choice since the results should maybe have a different "info" but there is no "info" on the results file so this seems the best option to prevent errors without changing the API.

@spacether
Copy link

FYI this is causing errors like:

/root/.cache/pypoetry/virtualenvs/inspection-api-QMca2cA6-py3.10/lib/python3.10/site-packages/mmengine/evaluator/evaluator.py:79: in evaluate
    _results = metric.evaluate(size)
/root/.cache/pypoetry/virtualenvs/inspection-api-QMca2cA6-py3.10/lib/python3.10/site-packages/mmengine/evaluator/metric.py:133: in evaluate
    _metrics = self.compute_metrics(results)  # type: ignore
/root/.cache/pypoetry/virtualenvs/inspection-api-QMca2cA6-py3.10/lib/python3.10/site-packages/mmdet/evaluation/metrics/coco_metric.py:462: in compute_metrics
    coco_dt = self._coco_api.loadRes(predictions)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <mmdet.datasets.api_wrappers.coco_api.COCO object at 0x7fd14d10f910>
resFile = [{'bbox': [1696.877197265625, 0.0, 542.33935546875, 1026.14990234375], 'category_id': 1, 'image_id': 0, 'score': 0.536...6142578125, 1356.0439529418945, 641.5918579101562], 'category_id': 1, 'image_id': 0, 'score': 0.5167234539985657}, ...]
    def loadRes(self, resFile):
        """
        Load result file and return a result api object.
        :param   resFile (str)     : file name of result file
        :return: res (obj)         : result api object
        """
        res = COCO()
>       res.dataset['info'] = copy.deepcopy(self.dataset['info'])
E       KeyError: 'info'

Can you please enable issues on your repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants