open-mmlab/mmdetection · error · RuntimeError
results does not contain masks.
Error message
results does not contain masks.
What it means
CopyPaste transform needs source objects; when results lack 'gt_masks' it can only synthesize object masks from boxes if paste_by_box=True. With paste_by_box=False and no gt_masks it raises RuntimeError.
Source
Thrown at mmdet/datasets/transforms/transforms.py:3086
def get_gt_masks(self, results: dict) -> BitmapMasks:
"""Get gt_masks originally or generated based on bboxes.
If gt_masks is not contained in results,
it will be generated based on gt_bboxes.
Args:
results (dict): Result dict.
Returns:
BitmapMasks: gt_masks, originally or generated based on bboxes.
"""
if results.get('gt_masks', None) is not None:
if self.paste_by_box:
warnings.warn('gt_masks is already contained in results, '
'so paste_by_box is disabled.')
return results['gt_masks']
else:
if not self.paste_by_box:
raise RuntimeError('results does not contain masks.')
return results['gt_bboxes'].create_masks(results['img'].shape[:2])
def _select_object(self, results: dict) -> dict:
"""Select some objects from the source results."""
bboxes = results['gt_bboxes']
labels = results['gt_bboxes_labels']
masks = self.get_gt_masks(results)
ignore_flags = results['gt_ignore_flags']
selected_inds = self._get_selected_inds(bboxes.shape[0])
selected_bboxes = bboxes[selected_inds]
selected_labels = labels[selected_inds]
selected_masks = masks[selected_inds]
selected_ignore_flags = ignore_flags[selected_inds]
results['gt_bboxes'] = selected_bboxes
results['gt_bboxes_labels'] = selected_labelsView on GitHub (pinned to cfd5d3a985)
Solutions
- Set paste_by_box=True in the CopyPaste config so masks are created from gt_bboxes
- Provide gt_masks in the source results (enable with_mask=True in the aux pipeline)
- Do not use CopyPaste on bbox-only datasets
Example fix
# before dict(type='CopyPaste', paste_by_box=False) # after dict(type='CopyPaste', paste_by_box=True)
Defensive patterns
Strategy: validation
Validate before calling
assert results.get('gt_masks') is not None or self.paste_by_box, 'need gt_masks or paste_by_box=True' Prevention
- Set paste_by_box=True for bbox-only sources
- Ensure aux dataset pipelines provide masks when needed
When it happens
Trigger: Configuring dict(type='CopyPaste', paste_by_box=False) on a dataset/branch that provides only bboxes (no masks), so _get_source_mask has nothing to return.
Common situations: Using CopyPaste on detection-only data; or mis-set paste_by_box when the auxiliary dataset has no mask annotations.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid text mode "{self.text_mode}".
- The type of frame_range must be int or list.
- {metric} is not in results
- metric must be a list or a str.
- metric {metric} is not supported.
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/f5579ed3b8416839.
Report an issue: GitHub.