open-mmlab/mmdetection · error · TypeError

The annotation file of Open Images Challenge should be a txt

Error message

The annotation file of Open Images Challenge should be a txt file.

What it means

OpenImagesChallenge dataset in mmdet requires the annotation file to be a .txt file (the Challenge subset ships CSV-like txt annotation files, unlike the standard Open Images which uses a CSV). The constructor checks the file extension and raises TypeError immediately before loading anything, so no data is read from a wrongly named/typed file.

Source

Thrown at mmdet/datasets/openimages.py:311

            self.hierarchy_file = osp.join(self.data_root, self.hierarchy_file)
        if self.image_level_ann_file and not is_abs(self.image_level_ann_file):
            self.image_level_ann_file = osp.join(self.data_root,
                                                 self.image_level_ann_file)


@DATASETS.register_module()
class OpenImagesChallengeDataset(OpenImagesDataset):
    """Open Images Challenge dataset for detection.

    Args:
        ann_file (str): Open Images Challenge box annotation in txt format.
    """

    METAINFO: dict = dict(dataset_type='oid_challenge')

    def __init__(self, ann_file: str, **kwargs) -> None:
        if not ann_file.endswith('txt'):
            raise TypeError('The annotation file of Open Images Challenge '
                            'should be a txt file.')

        super().__init__(ann_file=ann_file, **kwargs)

    def load_data_list(self) -> List[dict]:
        """Load annotations from an annotation file named as ``self.ann_file``

        Returns:
            List[dict]: A list of annotation.
        """
        classes_names, label_id_mapping = self._parse_label_file(
            self.label_file)
        self._metainfo['classes'] = classes_names
        self.label_id_mapping = label_id_mapping

        if self.image_level_ann_file is not None:
            img_level_anns = self._parse_img_level_ann(
                self.image_level_ann_file)

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Point ann_file at the Open Images Challenge annotation txt file (e.g. challenge2018_train_bbox.csv is actually txt-named in mmdet splits — use the file provided by the dataset preparation script, ending in .txt)
  2. If your annotations are genuinely in CSV format, use mmdet.datasets.OpenImagesDataset instead of the Challenge variant
  3. Rename your annotation file to have a .txt extension if the content is already the challenge txt format
  4. Verify the path: print ann_file and confirm it ends with 'txt' before constructing the dataset

Example fix

# before
dataset = dict(type='OpenImagesChallengeDataset', ann_file='annotations/challenge2018_train_bbox.csv')
# after
dataset = dict(type='OpenImagesChallengeDataset', ann_file='annotations/challenge2018_train_bbox.txt')
Defensive patterns

Strategy: validation

Validate before calling

ann_file = 'annotations/challenge2018_train_bbox.txt'
assert ann_file.endswith('txt'), 'OpenImagesChallenge annotation must be a .txt file'
dataset = OpenImagesChallengeDataset(ann_file=ann_file, data_prefix=dict(img='img/'))

Type guard

def is_valid_oid_ann_file(path: str) -> bool:
    return isinstance(path, str) and path.endswith('txt') and os.path.isfile(path)

Prevention

When it happens

Trigger: Instantiating OpenImagesChallengeDataset (or building a train_dataloader around it in a config) with ann_file that does not end with 'txt', e.g. pointing at a .csv/.json annotation file or a path missing the extension.

Common situations: Copying a config from the regular Open Images (csv) dataset, or renaming/moving annotation files so the .txt suffix is lost; also passing a URL or variable path without extension. Windows paths or hidden trailing characters can also defeat endswith('txt').

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/42fa17813321181b. Report an issue: GitHub.