{"record":{"id":"7dd5736e00b0ad0c","repo":"roboflow/supervision","slug":"coco-targets-must-be-provided","errorCode":null,"errorMessage":"coco_targets must be provided","messagePattern":"coco_targets must be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/mean_average_precision.py","lineNumber":701,"sourceCode":"    \"\"\"\n\n    def __init__(\n        self,\n        coco_targets: EvaluationDataset,\n        coco_predictions: EvaluationDataset,\n        metric_target: MetricTarget = MetricTarget.BOXES,\n    ) -> None:\n        \"\"\"\n        Constructor of COCOEvaluator object.\n\n        Args:\n            coco_targets: The dataset with the ground truths.\n            coco_predictions: The dataset with the predictions.\n            metric_target: The type of detection data used to compute the IoU -\n                boxes, masks or oriented bounding boxes.\n        \"\"\"\n        if coco_targets is None:\n            raise ValueError(\"coco_targets must be provided\")\n        if coco_predictions is None:\n            raise ValueError(\"coco_predictions must be provided\")\n\n        self.coco_targets = coco_targets\n        self.coco_predictions = coco_predictions\n        self.metric_target = metric_target\n        # List of dictionaries containing the evaluation results\n        # len(eval_imgs) = (categories) * (area_ranges) * (images)\n        # For COCO 2017: len(eval_images) = 80 * 4 * 5000 = 1600000\n        self.eval_imgs: list[_TypeEvaluationImageResult | None] = []\n        # Dictionary of accumulated results\n        self.results: dict[str, object] = {}\n        # Dictionary of targets for evaluation\n        self._targets: defaultdict[tuple[int, int], list[_TypeCocoDict]] = defaultdict(\n            list\n        )\n        self._predictions: defaultdict[tuple[int, int], list[_TypeCocoDict]] = (\n            defaultdict(list)","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/mean_average_precision.py#L683-L719","documentation":"COCOEvaluator, the COCO-backend evaluator inside MeanAveragePrecision, requires both a ground-truth and a predictions dataset. This ValueError fires from its constructor when coco_targets is None. The parameters have no default that makes sense, so the guard turns an accidental None (e.g. a variable that failed to load) into an explicit failure instead of an AttributeError deep inside evaluation.","triggerScenarios":"COCOEvaluator(None, coco_det) because the ground-truth JSON failed to parse or the file path was wrong so the loader returned None; a function that conditionally loads targets (try/except returning None) and passes the result unchecked; direct instantiation of COCOEvaluator by user code (it is internal to the mAP pipeline).","commonSituations":"Silent-failure loaders (json.load wrapped in except: return None); wrong file paths in config; empty argument after refactoring; users reaching for the internal COCO API instead of MeanAveragePrecision.update().","solutions":["Check the loader result: if coco_targets is None: raise with your file path/context before constructing","Fix the underlying load (path, JSON validity, schema) so a real EvaluationDataset is produced","Prefer the public API: mAP via MeanAveragePrecision().update(preds, targets).compute() which builds datasets internally","Add defensive asserts at pipeline boundaries where datasets enter"],"exampleFix":"# before\ncoco_gt = try_load(gt_path)          # returns None on failure\n evaluator = COCOEvaluator(coco_gt, coco_det)   # boom\n\n# after\ncoco_gt = try_load(gt_path)\nif coco_gt is None:\n    raise FileNotFoundError(f'could not load ground truth from {gt_path}')\nevaluator = COCOEvaluator(coco_gt, coco_det)","handlingStrategy":"validation","validationCode":"if coco_targets is None:\n    raise ValueError(f'ground truth failed to load from {gt_path!r}')\nevaluator = COCOEvaluator(coco_targets, coco_predictions)","typeGuard":null,"tryCatchPattern":"try:\n    COCOEvaluator(gt, det)\nexcept ValueError as e:\n    if 'coco_targets' in str(e):\n        raise RuntimeError('ground-truth dataset missing — check loader/paths') from e\n    raise","preventionTips":["Make loaders raise instead of returning None","Prefer the public MeanAveragePrecision API which builds datasets internally","Validate inputs at pipeline entry points"],"tags":["metrics","mean-average-precision","coco","null-check","constructor-validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}