open-mmlab/mmdetection · warning
There is overlap between pos and neg sample.
Error message
There is overlap between pos and neg sample.
What it means
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.
Source
Thrown at mmdet/models/dense_heads/yolo_head.py:370
neg_map (Tensor): The negative masks for a single level.
Returns:
tuple:
loss_cls (Tensor): Classification loss.
loss_conf (Tensor): Confidence loss.
loss_xy (Tensor): Regression loss of x, y coordinate.
loss_wh (Tensor): Regression loss of w, h coordinate.
"""
num_imgs = len(pred_map)
pred_map = pred_map.permute(0, 2, 3,
1).reshape(num_imgs, -1, self.num_attrib)
neg_mask = neg_map.float()
pos_mask = target_map[..., 4]
pos_and_neg_mask = neg_mask + pos_mask
pos_mask = pos_mask.unsqueeze(dim=-1)
if torch.max(pos_and_neg_mask) > 1.:
warnings.warn('There is overlap between pos and neg sample.')
pos_and_neg_mask = pos_and_neg_mask.clamp(min=0., max=1.)
pred_xy = pred_map[..., :2]
pred_wh = pred_map[..., 2:4]
pred_conf = pred_map[..., 4]
pred_label = pred_map[..., 5:]
target_xy = target_map[..., :2]
target_wh = target_map[..., 2:4]
target_conf = target_map[..., 4]
target_label = target_map[..., 5:]
loss_cls = self.loss_cls(pred_label, target_label, weight=pos_mask)
loss_conf = self.loss_conf(
pred_conf, target_conf, weight=pos_and_neg_mask)
loss_xy = self.loss_xy(pred_xy, target_xy, weight=pos_mask)
loss_wh = self.loss_wh(pred_wh, target_wh, weight=pos_mask)
View on GitHub (pinned to cfd5d3a985)
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
Defensive patterns
Strategy: validation
Validate before calling
# during loss computation debug:
overlap = (neg_mask.float() + pos_mask).max()
assert overlap <= 1. + 1e-6, f'pos/neg overlap: {overlap}' Prevention
- Unit-test target assignment on synthetic batches
- Treat the warning as a signal to review custom neg_map logic
When it happens
Trigger: 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.
Common situations: Custom target assignment code, unusual downsample ratios, or modified anchor settings in the legacy yolo_head.
Related errors
- RandomAffine only supports bbox.
- The annotation file of Open Images Challenge should be a txt
- Invalid text mode "{self.text_mode}".
- No sample in split "{self.split}".
- sampler should be an instance of ``Sampler``, but got {sampl
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/6a1c326e46dc59ec.
Report an issue: GitHub.