open-mmlab/mmdetection · error · NotImplementedError

RandomAffine only supports bbox.

Error message

RandomAffine only supports bbox.

What it means

RandomAffine (YOLO-style) supports only bounding-box annotations; after filtering boxes it raises NotImplementedError if 'gt_masks' is present in results.

Source

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

        results['img'] = img
        results['img_shape'] = img.shape[:2]

        bboxes = results['gt_bboxes']
        num_bboxes = len(bboxes)
        if num_bboxes:
            bboxes.project_(warp_matrix)
            if self.bbox_clip_border:
                bboxes.clip_([height, width])
            # remove outside bbox
            valid_index = bboxes.is_inside([height, width]).numpy()
            results['gt_bboxes'] = bboxes[valid_index]
            results['gt_bboxes_labels'] = results['gt_bboxes_labels'][
                valid_index]
            results['gt_ignore_flags'] = results['gt_ignore_flags'][
                valid_index]

            if 'gt_masks' in results:
                raise NotImplementedError('RandomAffine only supports bbox.')
        return results

    def __repr__(self):
        repr_str = self.__class__.__name__
        repr_str += f'(max_rotate_degree={self.max_rotate_degree}, '
        repr_str += f'max_translate_ratio={self.max_translate_ratio}, '
        repr_str += f'scaling_ratio_range={self.scaling_ratio_range}, '
        repr_str += f'max_shear_degree={self.max_shear_degree}, '
        repr_str += f'border={self.border}, '
        repr_str += f'border_val={self.border_val}, '
        repr_str += f'bbox_clip_border={self.bbox_clip_border})'
        return repr_str

    @staticmethod
    def _get_rotation_matrix(rotate_degrees: float) -> np.ndarray:
        radian = math.radians(rotate_degrees)
        rotation_matrix = np.array(
            [[np.cos(radian), -np.sin(radian), 0.],

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Remove with_mask/with_seg from LoadAnnotations
  2. For segmentation, swap RandomAffine for transforms supporting masks (e.g. RandomResize + RandomFlip + Crop)
  3. Keep RandomAffine only in detection-only pipelines

Example fix

# before
dict(type='LoadAnnotations', with_bbox=True, with_mask=True), dict(type='RandomAffine', scale=(0.5,1.15))
# after
dict(type='LoadAnnotations', with_bbox=True), dict(type='RandomAffine', scale=(0.5,1.15))
Defensive patterns

Strategy: validation

Validate before calling

assert 'gt_masks' not in results, 'RandomAffine is bbox-only'

Prevention

When it happens

Trigger: A training pipeline includes RandomAffine while results carry gt_masks (mask annotations loaded) — typically instance-seg datasets or with_mask=True.

Common situations: Adapting YOLOv5/YOLOX detection configs (which use RandomAffine) to instance segmentation datasets.

Related errors


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