| 391 | |
| 392 | |
| 393 | def eval_coco( |
| 394 | ground_truth: dict, |
| 395 | predictions: list[dict], |
| 396 | num_joints: int, |
| 397 | ) -> float | None: |
| 398 | try: |
| 399 | from pycocotools.coco import COCO |
| 400 | from pycocotools.cocoeval import COCOeval |
| 401 | |
| 402 | coco = COCO() |
| 403 | coco.dataset["annotations"] = ground_truth["annotations"] |
| 404 | coco.dataset["categories"] = ground_truth["categories"] |
| 405 | coco.dataset["images"] = ground_truth["images"] |
| 406 | coco.dataset["info"] = {"description": "Generated by DeepLabCut"} |
| 407 | coco.createIndex() |
| 408 | |
| 409 | coco_det = coco.loadRes(predictions) |
| 410 | coco_eval = COCOeval(coco, coco_det, iouType="keypoints") |
| 411 | coco_eval.params.kpt_oks_sigmas = np.array(num_joints * [0.1]) |
| 412 | coco_eval.evaluate() |
| 413 | coco_eval.accumulate() |
| 414 | coco_eval.summarize() |
| 415 | return float(coco_eval.stats[0]) |
| 416 | |
| 417 | except ModuleNotFoundError: |
| 418 | print("pycocotools is not installed") |