open-mmlab/mmdetection · error · RuntimeError

albumentations is not installed

Error message

albumentations is not installed

What it means

Albu (albumentations wrapper) transform in mmdet lazily imports albumentations; if it is absent, Compose is None and __init__ raises RuntimeError. The wrapper cannot build any augmentation pipeline without the library.

Source

Thrown at mmdet/datasets/transforms/transforms.py:1608

                p=0.1),
        ]

    Args:
        transforms (list[dict]): A list of albu transformations
        bbox_params (dict, optional): Bbox_params for albumentation `Compose`
        keymap (dict, optional): Contains
            {'input key':'albumentation-style key'}
        skip_img_without_anno (bool): Whether to skip the image if no ann left
            after aug. Defaults to False.
    """

    def __init__(self,
                 transforms: List[dict],
                 bbox_params: Optional[dict] = None,
                 keymap: Optional[dict] = None,
                 skip_img_without_anno: bool = False) -> None:
        if Compose is None:
            raise RuntimeError('albumentations is not installed')

        # Args will be modified later, copying it will be safer
        transforms = copy.deepcopy(transforms)
        if bbox_params is not None:
            bbox_params = copy.deepcopy(bbox_params)
        if keymap is not None:
            keymap = copy.deepcopy(keymap)
        self.transforms = transforms
        self.filter_lost_elements = False
        self.skip_img_without_anno = skip_img_without_anno

        # A simple workaround to remove masks without boxes
        if (isinstance(bbox_params, dict) and 'label_fields' in bbox_params
                and 'filter_lost_elements' in bbox_params):
            self.filter_lost_elements = True
            self.origin_label_fields = bbox_params['label_fields']
            bbox_params['label_fields'] = ['idx_mapper']
            del bbox_params['filter_lost_elements']

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install albumentations
  2. Confirm version compatibility (mmdet >=0.5 behavior differs): pip install albumentations>=0.5
  3. Drop the Albu transform from the pipeline if not needed

Example fix

# before
dict(type='Albu', transforms=[dict(type='RandomBrightnessContrast', p=0.5)])
# after: install first
# pip install albumentations>=1.0
# then keep the same config
Defensive patterns

Strategy: validation

Validate before calling

from mmdet.datasets.transforms import Albu
from mmdet.datasets.transforms.transforms import Compose
assert Compose is not None, 'albumentations not installed'

Try / catch

try:
    Albu(transforms=[dict(type='HorizontalFlip', p=0.5)])
except RuntimeError as e:
    if 'albumentations' in str(e):
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'albumentations'])

Prevention

When it happens

Trigger: Config contains dict(type='Albu', transforms=[...]) while the albumentations package is not installed in the environment.

Common situations: Copying a training config that uses Albu (e.g. some YOLOX or custom pipelines) into an environment without the extra; albumentations is an optional extra of mmdet.

Related errors


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