roboflow/supervision · error · ValueError

Detections confidence must be given for NMM to be executed.

Error message

Detections confidence must be given for NMM to be executed.

What it means

Detections.with_non_max_merge (with_nmm) merges overlapping boxes and computes a confidence-weighted merge; the weighting requires per-box scores. If self.confidence is None the method raises this ValueError before dispatching to the merge routine.

Source

Thrown at src/supervision/detection/core.py:3189

            is the tightest rectangle at the winner's orientation enclosing all
            corners contributed by every detection in the group. The winner is
            the highest-confidence detection in the group. The axis-aligned
            ``xyxy`` field is updated to the tight bounding box of that rect.
            For zero-rotation OBBs this equals the axis-aligned union exactly;
            for rotated OBBs the merged rect inherits the winner's rotation angle.
            Groups of size 1 keep the original OBB unchanged.

        Raises:
            ValueError: If `confidence` is None or `class_id` is None and
                class_agnostic is False.

        ![non-max-merging](https://media.roboflow.com/supervision-docs/non-max-merging.png){ align=center width="800" }
        """  # noqa: E501 // docs
        if len(self) == 0:
            return self

        if self.confidence is None:
            raise ValueError(
                "Detections confidence must be given for NMM to be executed."
            )

        predictions = self._build_nms_predictions(class_agnostic, "NMM")

        if self.mask is not None:
            merge_groups = mask_non_max_merge(
                predictions=predictions,
                masks=self.mask,
                iou_threshold=threshold,
                overlap_metric=overlap_metric,
            )
        elif ORIENTED_BOX_COORDINATES in self.data:
            merge_groups = oriented_box_non_max_merge(
                predictions=predictions,
                oriented_boxes=np.asarray(
                    self.data[ORIENTED_BOX_COORDINATES], dtype=np.float32
                ),

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Provide confidence at construction time from whatever scoring source exists.
  2. Use uniform scores np.ones(len(detections)) if you only need geometric merging and accept unweighted behavior.
  3. If no scores are meaningful, replace NMM with your own IoU-grouping + box averaging loop.

Example fix

# before
detections = sv.Detections(xyxy=boxes)  # no confidence
merged = detections.with_nmm(threshold=0.5)  # ValueError

# after
detections = sv.Detections(xyxy=boxes, confidence=np.ones(len(boxes)))
merged = detections.with_nmm(threshold=0.5)
Defensive patterns

Strategy: validation

Validate before calling

if detections.confidence is None:
    detections = sv.Detections(
        xyxy=detections.xyxy,
        class_id=detections.class_id,
        confidence=np.ones(len(detections), dtype=float),
    )
merged = detections.with_nmm(threshold=0.5)

Type guard

def has_confidence(dets: sv.Detections) -> bool:
    return dets.confidence is not None

Try / catch

try:
    merged = detections.with_nmm(threshold=0.5)
except ValueError as e:
    if 'confidence must be given' in str(e):
        raise ValueError('cannot weight NMM merge without scores') from e
    raise

Prevention

When it happens

Trigger: Calling detections.with_nmm(threshold=...) on a Detections created without confidence — e.g. from_sam output, VLM connectors (PaliGemma, DeepSeek-VL2, Moondream) that populate only class_name, or manual cls(xyxy=...) construction.

Common situations: Merging duplicate SAM/VLM boxes that have no scores; constructing Detections from external detectors (HTTP APIs, ONNX custom pipelines) that don't expose scores; post-processing steps that drop the confidence field.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/99544dab3ef0c848. Report an issue: GitHub.