open-mmlab/mmdetection · error · NotImplementedError
Albu only supports BitMap masks now
Error message
Albu only supports BitMap masks now
What it means
Albu can only pass bitmap (instance) masks to albumentations; PolygonMasks (polygon annotations) are not supported and raise NotImplementedError during _preprocess_results.
Source
Thrown at mmdet/datasets/transforms/transforms.py:1725
def _preprocess_results(self, results: dict) -> tuple:
"""Pre-processing results to facilitate the use of Albu."""
if 'bboxes' in results:
# to list of boxes
if not isinstance(results['bboxes'], HorizontalBoxes):
raise NotImplementedError(
'Albu only supports horizontal boxes now')
bboxes = results['bboxes'].numpy()
results['bboxes'] = [x for x in bboxes]
# add pseudo-field for filtration
if self.filter_lost_elements:
results['idx_mapper'] = np.arange(len(results['bboxes']))
# TODO: Support mask structure in albu
ori_masks = None
if 'masks' in results:
if isinstance(results['masks'], PolygonMasks):
raise NotImplementedError(
'Albu only supports BitMap masks now')
ori_masks = results['masks']
if albumentations.__version__ < '0.5':
results['masks'] = results['masks'].masks
else:
results['masks'] = [mask for mask in results['masks'].masks]
return results, ori_masks
def _postprocess_results(
self,
results: dict,
ori_masks: Optional[Union[BitmapMasks,
PolygonMasks]] = None) -> dict:
"""Post-processing Albu output."""
# albumentations may return np.array or list on different versions
if 'gt_bboxes_labels' in results and isinstance(
results['gt_bboxes_labels'], list):View on GitHub (pinned to cfd5d3a985)
Solutions
- Set poly2mask=True in LoadAnnotations so masks become bitmap BitMasks
- Or remove Albu and use native mmdet transforms for mask pipelines
- Keep Albu only for detection (bbox-only) pipelines
Example fix
# before pipeline=[dict(type='LoadAnnotations', with_mask=True, poly2mask=False), dict(type='Albu', ...)] # after pipeline=[dict(type='LoadAnnotations', with_mask=True, poly2mask=True), dict(type='Albu', ...)]
Defensive patterns
Strategy: validation
Validate before calling
from mmdet.structures.mask import PolygonMasks
if 'masks' in results:
assert not isinstance(results['masks'], PolygonMasks), 'Albu needs bitmap masks' Prevention
- Set poly2mask=True when using Albu on segmentation data
- Prefer native mmdet transforms for mask-heavy pipelines
When it happens
Trigger: Using Albu in a pipeline where results['masks'] is a PolygonMasks object (e.g. instance-seg configs loading polygon annotations, typically COCO via LoadAnnotations with poly2mask=False).
Common situations: Adding Albu augmentations to instance segmentation training configs that use polygon masks.
Related errors
- albumentations is not installed
- type must be a str or valid type, but got {type(obj_type)}
- Albu only supports horizontal boxes now
- The `in_channels` of SOLOv2MaskFeatHead and SOLOv2Head shoul
- The annotation file of Open Images Challenge should be a txt
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/487903758e03f7c2.
Report an issue: GitHub.