facebookresearch/detectron2 · error · KeyError
Dataset '{}' is not registered! Available datasets are: {}
Error message
Dataset '{}' is not registered! Available datasets are: {} What it means
DatasetCatalog.get(name) looks up the registered loader for the dataset name; a KeyError from the lookup is re-raised with a message listing all registered dataset names so you can see what's available.
Source
Thrown at detectron2/data/catalog.py:53
"""
assert callable(func), "You must register a function with `DatasetCatalog.register`!"
assert name not in self, "Dataset '{}' is already registered!".format(name)
self[name] = func
def get(self, name):
"""
Call the registered function and return its results.
Args:
name (str): the name that identifies a dataset, e.g. "coco_2014_train".
Returns:
list[dict]: dataset annotations.
"""
try:
f = self[name]
except KeyError as e:
raise KeyError(
"Dataset '{}' is not registered! Available datasets are: {}".format(
name, ", ".join(list(self.keys()))
)
) from e
return f()
def list(self) -> List[str]:
"""
List all registered datasets.
Returns:
list[str]
"""
return list(self.keys())
def remove(self, name):
"""
Alias of ``pop``.View on GitHub (pinned to a2f4a8771a)
Solutions
- Ensure the registering import runs: from my_project import register_datasets before building loaders
- Fix the dataset name string to exactly match the registration (case-sensitive); the error lists available names
- If the dataset should be built-in, import detectron2.data.datasets (or the specific builtin module)
Example fix
# before
DatasetCatalog.get("mydata_train") # not registered
# after
from mydata import register_mydata # calls DatasetCatalog.register("mydata_train", ...)
register_mydata()
d = DatasetCatalog.get("mydata_train") Defensive patterns
Strategy: validation
Validate before calling
from detectron2.data import DatasetCatalog
assert name in DatasetCatalog.list(), f"{name} not registered; have: {DatasetCatalog.list()}" Type guard
def dataset_registered(name: str) -> bool:
return name in DatasetCatalog.list() Try / catch
try:
dicts = DatasetCatalog.get(name)
except KeyError as e:
if "not registered" in str(e):
import my_datasets # module that registers
dicts = DatasetCatalog.get(name)
else:
raise Prevention
- Import dataset registration modules at program entry
- Add a startup check that all cfg.DATASETS.TRAIN/TEST names are registered
- Use exact, case-sensitive dataset name constants
When it happens
Trigger: Calling DatasetCatalog.get('my_train') when only register_instances-style names exist; using cfg.DATASETS.TRAIN=('coco_2017_train_xyz',) with a typo; calling get before your register call ran.
Common situations: Forgetting to import the module that registers the dataset (e.g. custom dataset script); typos in dataset names; expecting built-in registration without importing detectron2.data.datasets.
Related errors
- Attribute '{}' does not exist in the metadata of dataset '{}
- Attribute '{key}' does not exist in the metadata of dataset
- Cannot match one checkpoint key to multiple keys in the mode
- Class with @configurable must have a 'from_config' classmeth
- {name} must take 'cfg' as the first argument!
AI-assisted analysis of facebookresearch/detectron2@a2f4a8771a (2026-08-27).
Data as JSON: /api/errors/f992602034e2a7fb.
Report an issue: GitHub.