open-mmlab/mmdetection · info
gt_masks is already contained in results, so paste_by_box is
Error message
gt_masks is already contained in results, so paste_by_box is disabled.
What it means
Warning from CopyPaste transform (_get_gt_masks): results already contains 'gt_masks', so the paste_by_box mode (generating masks from boxes) is disabled and existing masks are returned unchanged.
Source
Thrown at mmdet/datasets/transforms/transforms.py:3081
@cache_randomness
def _get_selected_inds(self, num_bboxes: int) -> np.ndarray:
max_num_pasted = min(num_bboxes + 1, self.max_num_pasted)
num_pasted = np.random.randint(0, max_num_pasted)
return np.random.choice(num_bboxes, size=num_pasted, replace=False)
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]View on GitHub (pinned to cfd5d3a985)
Solutions
- Set paste_by_box=False in the CopyPaste transform (masks are used anyway)
- Remove the flag from config to silence the warning
- Keep as-is if harmless; behavior is correct (uses real masks)
Example fix
# before train_pipeline = [dict(type='CopyPaste', paste_by_box=True), ...] # after train_pipeline = [dict(type='CopyPaste', paste_by_box=False), ...]
Defensive patterns
Strategy: validation
Validate before calling
if 'gt_masks' in results and copy_paste_cfg.get('paste_by_box', False):
copy_paste_cfg['paste_by_box'] = False # masks already exist Prevention
- Set paste_by_box=False in segmentation pipelines
- Understand paste_by_box is only a detection-data fallback
When it happens
Trigger: Configuring CopyPaste with paste_by_box=True on a pipeline where gt_masks already exist (segmentation annotations loaded).
Common situations: Instance segmentation configs reused with copy-paste augmentation; paste_by_box is a fallback for detection-only data, so it is redundant — and warned about — when masks are present.
Related errors
- dataset_meta or class names are not saved in the checkpoint'
- Checkpoint is not loaded, and the inference result is calcul
- weights is None, use COCO classes by default.
- palette does not exist, random is used by default. You can a
- Currently does not support saving datasample when return_dat
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/a4509ea957d3264e.
Report an issue: GitHub.