facebookresearch/detectron2 · error · KeyError
No built-in metadata for dataset {}
Error message
No built-in metadata for dataset {} What it means
detectron2's builtin metadata registry only knows a fixed set of dataset names (COCO, cityscapes, etc.). _get_builtin_metadata raises KeyError when asked for metadata of a dataset name that has no builtin entry.
Source
Thrown at detectron2/data/datasets/builtin_meta.py:350
"keypoint_connection_rules": KEYPOINT_CONNECTION_RULES,
}
elif dataset_name == "cityscapes":
# fmt: off
CITYSCAPES_THING_CLASSES = [
"person", "rider", "car", "truck",
"bus", "train", "motorcycle", "bicycle",
]
CITYSCAPES_STUFF_CLASSES = [
"road", "sidewalk", "building", "wall", "fence", "pole", "traffic light",
"traffic sign", "vegetation", "terrain", "sky", "person", "rider", "car",
"truck", "bus", "train", "motorcycle", "bicycle",
]
# fmt: on
return {
"thing_classes": CITYSCAPES_THING_CLASSES,
"stuff_classes": CITYSCAPES_STUFF_CLASSES,
}
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
View on GitHub (pinned to a2f4a8771a)
Solutions
- Register your own metadata: MetadataCatalog.set('mydataset_train', thing_classes=[...]) before use
- Check the exact dataset name spelling against the keys in detectron2/data/datasets/builtin_meta.py
- For custom COCO-format data use register_coco_instances which sets metadata from the json's categories
Example fix
# before
meta = MetadataCatalog.get('mydata_train')
# after
from detectron2.data import MetadataCatalog
MetadataCatalog.set('mydata_train', thing_classes=['cat', 'dog'])
meta = MetadataCatalog.get('mydata_train') Defensive patterns
Strategy: validation
Validate before calling
from detectron2.data import MetadataCatalog
name = 'mydata_train'
if not MetadataCatalog.contains(name):
MetadataCatalog.set(name, thing_classes=['cat', 'dog']) Try / catch
try:
meta = MetadataCatalog.get(name)
except (KeyError, AssertionError):
MetadataCatalog.set(name, thing_classes=classes)
meta = MetadataCatalog.get(name) Prevention
- Always register metadata for custom dataset names before training
- Use register_coco_instances/register_lvis_instances helpers which set metadata
- Double-check dataset name strings against builtin_meta.py keys
When it happens
Trigger: Calling MetadataCatalog.get(name) (or a registration helper) for a name like 'mydataset_train' without registering custom metadata first; or a typo/varied name such as 'coco_2017_trains' or 'cityscapes_fine_*_val' variant not covered by builtin_meta.py keys.
Common situations: Training on a custom or renamed dataset without MetadataCatalog.set(); dataset name typos; splitting/renaming builtin datasets (e.g. 'coco_2017_val_100') that are expected to hit builtin entries but miss the key.
Related errors
- No built-in metadata for dataset {}
- Attribute '{}' does not exist in the metadata of dataset '{}
- Attribute '{key}' does not exist in the metadata of dataset
- Encountered category_id={annotation_category_id} but this id
- Cannot match one checkpoint key to multiple keys in the mode
AI-assisted analysis of facebookresearch/detectron2@a2f4a8771a (2026-08-27).
Data as JSON: /api/errors/1598f9ceeeb7acac.
Report an issue: GitHub.