{"record":{"id":"6a1c326e46dc59ec","repo":"open-mmlab/mmdetection","slug":"there-is-overlap-between-pos-and-neg-sample","errorCode":null,"errorMessage":"There is overlap between pos and neg sample.","messagePattern":"There is overlap between pos and neg sample\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/dense_heads/yolo_head.py","lineNumber":370,"sourceCode":"            neg_map (Tensor): The negative masks for a single level.\n\n        Returns:\n            tuple:\n                loss_cls (Tensor): Classification loss.\n                loss_conf (Tensor): Confidence loss.\n                loss_xy (Tensor): Regression loss of x, y coordinate.\n                loss_wh (Tensor): Regression loss of w, h coordinate.\n        \"\"\"\n\n        num_imgs = len(pred_map)\n        pred_map = pred_map.permute(0, 2, 3,\n                                    1).reshape(num_imgs, -1, self.num_attrib)\n        neg_mask = neg_map.float()\n        pos_mask = target_map[..., 4]\n        pos_and_neg_mask = neg_mask + pos_mask\n        pos_mask = pos_mask.unsqueeze(dim=-1)\n        if torch.max(pos_and_neg_mask) > 1.:\n            warnings.warn('There is overlap between pos and neg sample.')\n            pos_and_neg_mask = pos_and_neg_mask.clamp(min=0., max=1.)\n\n        pred_xy = pred_map[..., :2]\n        pred_wh = pred_map[..., 2:4]\n        pred_conf = pred_map[..., 4]\n        pred_label = pred_map[..., 5:]\n\n        target_xy = target_map[..., :2]\n        target_wh = target_map[..., 2:4]\n        target_conf = target_map[..., 4]\n        target_label = target_map[..., 5:]\n\n        loss_cls = self.loss_cls(pred_label, target_label, weight=pos_mask)\n        loss_conf = self.loss_conf(\n            pred_conf, target_conf, weight=pos_and_neg_mask)\n        loss_xy = self.loss_xy(pred_xy, target_xy, weight=pos_mask)\n        loss_wh = self.loss_wh(pred_wh, target_wh, weight=pos_mask)\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/dense_heads/yolo_head.py#L352-L388","documentation":"YOLOHead (v1) loss warns when some anchors are simultaneously marked positive (object present) and negative (background), i.e. neg_mask + pos_mask > 1 somewhere. It clamps the combined mask to [0,1] and continues, but the target assignment is inconsistent and training quality may suffer.","triggerScenarios":"Training YOLOv1/v2-style head where neg_map construction overlaps target_map[..., 4] objectness positions — typically due to ignore-region/neighbor-anchor logic mis-marking negatives.","commonSituations":"Custom target assignment code, unusual downsample ratios, or modified anchor settings in the legacy yolo_head.","solutions":["Inspect the target assignment producing neg_map and pos_mask; ensure background mask excludes cells with objectness target 1","If unmodified configs are used, treat as benign and rely on the clamp; verify mAP isn't degraded","Update to the maintained YOLO heads (YOLOv3+) if feasible"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# during loss computation debug:\noverlap = (neg_mask.float() + pos_mask).max()\nassert overlap <= 1. + 1e-6, f'pos/neg overlap: {overlap}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unit-test target assignment on synthetic batches","Treat the warning as a signal to review custom neg_map logic"],"tags":["mmdet","yolo","training","target-assignment"],"backgroundTag":"training-target-overlap","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}