{"record":{"id":"b0e2d5500a6edaf6","repo":"roboflow/supervision","slug":"detections-confidence-must-be-given-for-soft-nms-t","errorCode":null,"errorMessage":"Detections confidence must be given for Soft-NMS to be executed.","messagePattern":"Detections confidence must be given for Soft-NMS to be executed\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":3118,"sourceCode":"                (like `with_nms`). If `None` (default), all detections are\n                kept, with their confidence rescaled in place on the returned\n                copy.\n\n        Returns:\n            A new Detections object with decayed confidence scores and,\n                if `score_threshold` is given, filtered to a real subset.\n                The original `Detections` instance is never modified.\n\n        Raises:\n            ValueError: If `confidence` is None.\n                If `class_id` is None and class_agnostic is False.\n                If `sigma` is not greater than `0`.\n        \"\"\"\n        if len(self) == 0:\n            return self\n\n        if self.confidence is None:\n            raise ValueError(\n                \"Detections confidence must be given for Soft-NMS to be executed.\"\n            )\n\n        predictions = self._build_nms_predictions(class_agnostic, \"Soft-NMS\")\n\n        if self.mask is not None:\n            decayed_confidence = mask_soft_non_max_suppression(\n                predictions=predictions,\n                masks=self.mask,\n                sigma=sigma,\n            )\n        else:\n            decayed_confidence = box_soft_non_max_suppression(\n                predictions=predictions,\n                sigma=sigma,\n            )\n\n        result = self.select(np.arange(len(self)))","sourceCodeStart":3100,"sourceCodeEnd":3136,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L3100-L3136","documentation":"Detections.with_soft_non_max_suppression (with_soft_nms) decays confidence values of overlapping boxes using a Gaussian; the algorithm is undefined without scores. When self.confidence is None it raises this ValueError before any dispatch.","triggerScenarios":"Calling detections.with_soft_nms(sigma=..., ...) on a Detections lacking confidence — SAM/segmentation outputs, VLM connectors that return only class names, or manual construction without the confidence argument.","commonSituations":"Same family as NMS/NMM: score-less connectors (from_sam, from_paligemma-style outputs), hand-assembled boxes, or pipelines where confidence was stripped by an earlier with_nmsless transform or custom slicing that dropped fields.","solutions":["Attach real scores if available: cls(xyxy=..., confidence=scores).","Attach uniform dummy confidence (np.ones(len(detections))) only when you accept IoU-only soft suppression semantics.","Skip soft-NMS for score-less sources and deduplicate by geometry/text instead."],"exampleFix":"# before\ndetections = sv.Detections(xyxy=boxes)  # no confidence\nout = detections.with_soft_nms(sigma=0.5)\n\n# after\ndetections = sv.Detections(xyxy=boxes, confidence=np.ones(len(boxes)))\nout = detections.with_soft_nms(sigma=0.5)","handlingStrategy":"validation","validationCode":"if detections.confidence is None:\n    detections = sv.Detections(\n        xyxy=detections.xyxy,\n        class_id=detections.class_id,\n        confidence=np.ones(len(detections), dtype=float),\n    )\nout = detections.with_soft_nms(sigma=0.5)","typeGuard":"def soft_nms_ready(dets: sv.Detections) -> bool:\n    return dets.confidence is not None and (dets.class_id is not None or True)","tryCatchPattern":"try:\n    out = detections.with_soft_nms(sigma=0.5)\nexcept ValueError as e:\n    if 'confidence must be given' in str(e):\n        out = detections  # no scores -> nothing to decay\n    else:\n        raise","preventionTips":["Attach scores before any suppression stage","Keep confidence column through slicing/filtering","Remember with_soft_nms also needs class_id unless class_agnostic=True"],"tags":["soft-nms","confidence","detections","suppression"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}