| 372 | |
| 373 | |
| 374 | def eval_coco( |
| 375 | ground_truth: dict, |
| 376 | predictions: list[dict], |
| 377 | num_joints: int, |
| 378 | ) -> float | None: |
| 379 | try: |
| 380 | from pycocotools.coco import COCO |
| 381 | from pycocotools.cocoeval import COCOeval |
| 382 | |
| 383 | coco = COCO() |
| 384 | coco.dataset["annotations"] = ground_truth["annotations"] |
| 385 | coco.dataset["categories"] = ground_truth["categories"] |
| 386 | coco.dataset["images"] = ground_truth["images"] |
| 387 | coco.dataset["info"] = {"description": "Generated by DeepLabCut"} |
| 388 | coco.createIndex() |
| 389 | |
| 390 | coco_det = coco.loadRes(predictions) |
| 391 | coco_eval = COCOeval(coco, coco_det, iouType="keypoints") |
| 392 | coco_eval.params.kpt_oks_sigmas = np.array(num_joints * [0.1]) |
| 393 | coco_eval.evaluate() |
| 394 | coco_eval.accumulate() |
| 395 | coco_eval.summarize() |
| 396 | return float(coco_eval.stats[0]) |
| 397 | |
| 398 | except ModuleNotFoundError: |
| 399 | print("pycocotools is not installed") |