{"record":{"id":"2ca5dc1ed57b1f52","repo":"roboflow/supervision","slug":"the-number-of-icon-paths-provided-len-icon-path","errorCode":null,"errorMessage":"The number of icon paths provided ({len(icon_path)}) does not match the number of detections ({len(detections)}). Either provide a single icon path or one for each detection.","messagePattern":"The number of icon paths provided \\((.+?)\\) does not match the number of detections \\((.+?)\\)\\. Either provide a single icon path or one for each detection\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/annotators/core.py","lineNumber":2005,"sourceCode":"\n            available_icons = [\"roboflow.png\", \"lenny.png\"]\n            icon_paths = [np.random.choice(available_icons) for _ in detections]\n\n            icon_annotator = sv.IconAnnotator()\n            annotated_frame = icon_annotator.annotate(\n                scene=image.copy(),\n                detections=detections,\n                icon_path=icon_paths\n            )\n            ```\n\n        ![icon-annotator-example](https://media.roboflow.com/\n        supervision-annotator-examples/icon-annotator-example.png)\n        \"\"\"\n        if not isinstance(scene, np.ndarray):\n            return scene\n        if isinstance(icon_path, list) and len(icon_path) != len(detections):\n            raise ValueError(\n                f\"The number of icon paths provided ({len(icon_path)}) does not match \"\n                f\"the number of detections ({len(detections)}). Either provide a single\"\n                f\" icon path or one for each detection.\"\n            )\n\n        xy: npt.NDArray[np.int32] = detections.get_anchors_coordinates(\n            anchor=self.position\n        ).astype(int)\n\n        for detection_idx in range(len(detections)):\n            current_path = (\n                icon_path if isinstance(icon_path, str) else icon_path[detection_idx]\n            )\n            if current_path == \"\":\n                continue\n            icon = self._load_icon(current_path)\n            icon_h, icon_w = icon.shape[:2]\n","sourceCodeStart":1987,"sourceCodeEnd":2023,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/annotators/core.py#L1987-L2023","documentation":"Raised by `IconAnnotator.annotate` when `icon_path` is a list whose length differs from the number of detections. The API accepts either one path (applied to all detections) or exactly one path per detection; any other count is ambiguous and rejected before drawing.","triggerScenarios":"Calling `annotate(scene, detections, icon_path=[\"a.png\", \"b.png\"])` with 5 detections; filtering detections after building the per-detection icon list; passing a list of paths for multi-class icon sets while detections include all classes.","commonSituations":"Per-class icon lists sized by number of classes rather than number of detections; detections changing length between frames (tracking/filtering) while the icon list is static; empty detections combined with a non-empty icon list.","solutions":["Pass a single path string when every detection should get the same icon.","Otherwise rebuild the list per frame so `len(icon_path) == len(detections)`, deriving entries from `detections.class_id`.","Apply the same filter mask to the icon list that you applied to the detections."],"exampleFix":"# before\nicons = [\"dog.png\", \"cat.png\", \"bird.png\"]\ndetections = detections[detections.confidence > 0.5]  # len changed\nannotator.annotate(scene, detections, icon_path=icons)  # ValueError\n\n# after\nicon_by_class = {0: \"dog.png\", 1: \"cat.png\", 2: \"bird.png\"}\nicons = [icon_by_class[c] for c in detections.class_id]\nannotator.annotate(scene, detections, icon_path=icons)","handlingStrategy":"validation","validationCode":"if isinstance(icon_path, list):\n    assert len(icon_path) == len(detections), (\n        f\"{len(icon_path)} icons for {len(detections)} detections\"\n    )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a single string unless you truly need per-detection icons.","Derive per-detection icon lists from detections.class_id each frame."],"tags":["annotators","icons","alignment"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}