open-mmlab/mmdetection · error · KeyError
box type {name} has been registered
Error message
box type {name} has been registered What it means
mmdet keeps a global registry mapping box type names ('hbox', 'rbox', 'qbox') to classes. _register_box raises KeyError on duplicate registration to prevent ambiguous box-type semantics in convert/pack operations; force=True overwrites instead.
Source
Thrown at mmdet/structures/bbox/box_type.py:30
box_types: dict = {}
_box_type_to_name: dict = {}
box_converters: dict = {}
def _register_box(name: str, box_type: Type, force: bool = False) -> None:
"""Register a box type.
Args:
name (str): The name of box type.
box_type (type): Box mode class to be registered.
force (bool): Whether to override an existing class with the same
name. Defaults to False.
"""
assert issubclass(box_type, BaseBoxes)
name = name.lower()
if not force and (name in box_types or box_type in _box_type_to_name):
raise KeyError(f'box type {name} has been registered')
elif name in box_types:
_box_type = box_types.pop(name)
_box_type_to_name.pop(_box_type)
elif box_type in _box_type_to_name:
_name = _box_type_to_name.pop(box_type)
box_types.pop(_name)
box_types[name] = box_type
_box_type_to_name[box_type] = name
def register_box(name: str,
box_type: Type = None,
force: bool = False) -> Union[Type, Callable]:
"""Register a box type.
A record will be added to ``bbox_types``, whose key is the box type name
and value is the box type itself. Simultaneously, a reverse dictionaryView on GitHub (pinned to cfd5d3a985)
Solutions
- Pass force=True when re-registration is intentional (plugins overriding built-in behavior)
- Use a unique name for custom box types instead of colliding with 'hbox'/'rbox'/'qbox'
- Restart the kernel / avoid re-importing registration modules in notebooks
Example fix
# before register_box(MyBoxes, 'hbox') # KeyError: already registered # after register_box(MyBoxes, 'mybox') # unique name # or register_box(MyBoxes, 'hbox', force=True) # intentional override
Defensive patterns
Strategy: try-catch
Validate before calling
from mmdet.structures.bbox import box_types
name = 'mybox'
if name in box_types:
# already registered, skip or use force
pass Try / catch
try:
register_box(MyBoxes, 'mybox')
except KeyError as e:
if 'has been registered' in str(e):
register_box(MyBoxes, 'mybox', force=True) # if override intended
else:
raise Prevention
- Namespace custom box type names to avoid collisions
- Disable autoreload for modules that register global state
When it happens
Trigger: Calling get_box_type/register machinery twice for the same name — commonly importing a module that re-registers a box type (e.g. re-importing mmdet.structures in a notebook after autoreload, or a third-party plugin registering 'hbox' again without force).
Common situations: Jupyter %autoreload re-executing registration code, plugin packages registering a type name already used by mmdet, or module reloads in test suites.
Related errors
- LoadImageFromFile is not found in the test pipeline
- Visualization needs the "visualizer" termdefined in the conf
- Unsupported input type: {type(single_input)}
- panopticapi is not installed, please install it by: pip inst
- config must be a filename or Config object, but got {type(co
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/f2deb2e62be58011.
Report an issue: GitHub.