{"record":{"id":"a4509ea957d3264e","repo":"open-mmlab/mmdetection","slug":"gt-masks-is-already-contained-in-results-so-paste","errorCode":null,"errorMessage":"gt_masks is already contained in results, so paste_by_box is disabled.","messagePattern":"gt_masks is already contained in results, so paste_by_box is disabled\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"mmdet/datasets/transforms/transforms.py","lineNumber":3081,"sourceCode":"    @cache_randomness\n    def _get_selected_inds(self, num_bboxes: int) -> np.ndarray:\n        max_num_pasted = min(num_bboxes + 1, self.max_num_pasted)\n        num_pasted = np.random.randint(0, max_num_pasted)\n        return np.random.choice(num_bboxes, size=num_pasted, replace=False)\n\n    def get_gt_masks(self, results: dict) -> BitmapMasks:\n        \"\"\"Get gt_masks originally or generated based on bboxes.\n\n        If gt_masks is not contained in results,\n        it will be generated based on gt_bboxes.\n        Args:\n            results (dict): Result dict.\n        Returns:\n            BitmapMasks: gt_masks, originally or generated based on bboxes.\n        \"\"\"\n        if results.get('gt_masks', None) is not None:\n            if self.paste_by_box:\n                warnings.warn('gt_masks is already contained in results, '\n                              'so paste_by_box is disabled.')\n            return results['gt_masks']\n        else:\n            if not self.paste_by_box:\n                raise RuntimeError('results does not contain masks.')\n            return results['gt_bboxes'].create_masks(results['img'].shape[:2])\n\n    def _select_object(self, results: dict) -> dict:\n        \"\"\"Select some objects from the source results.\"\"\"\n        bboxes = results['gt_bboxes']\n        labels = results['gt_bboxes_labels']\n        masks = self.get_gt_masks(results)\n        ignore_flags = results['gt_ignore_flags']\n\n        selected_inds = self._get_selected_inds(bboxes.shape[0])\n\n        selected_bboxes = bboxes[selected_inds]\n        selected_labels = labels[selected_inds]","sourceCodeStart":3063,"sourceCodeEnd":3099,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/transforms.py#L3063-L3099","documentation":"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.","triggerScenarios":"Configuring CopyPaste with paste_by_box=True on a pipeline where gt_masks already exist (segmentation annotations loaded).","commonSituations":"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.","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)"],"exampleFix":"# before\ntrain_pipeline = [dict(type='CopyPaste', paste_by_box=True), ...]\n# after\ntrain_pipeline = [dict(type='CopyPaste', paste_by_box=False), ...]","handlingStrategy":"validation","validationCode":"if 'gt_masks' in results and copy_paste_cfg.get('paste_by_box', False):\n    copy_paste_cfg['paste_by_box'] = False  # masks already exist","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set paste_by_box=False in segmentation pipelines","Understand paste_by_box is only a detection-data fallback"],"tags":["python","warning","copy-paste","augmentation","segmentation"],"backgroundTag":"redundant-config-option","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}