{"library":"pycocoevalcap","title":"MS-COCO Caption Evaluation","description":"pycocoevalcap provides Python 3 support for evaluating image captions using standard MS-COCO metrics (BLEU, METEOR, ROUGE-L, CIDEr, SPICE). It is derived from the original Python 2.7 coco-caption repository and depends on the COCO API. The latest version is 1.2, released in November 2020, indicating a maintenance-oriented release cadence.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pycocoevalcap"],"cli":null},"imports":["from pycocoevalcap.eval import COCOEvalCap","from pycocoevalcap.bleu.bleu import Bleu","from pycocoevalcap.meteor.meteor import Meteor","from pycocoevalcap.rouge.rouge import Rouge","from pycocoevalcap.cider.cider import Cider","from pycocoevalcap.spice.spice import Spice"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import json\nfrom pycocoevalcap.eval import COCOEvalCap\n\n# Mock ground truth and predicted captions data\n# In a real scenario, these would be loaded from JSON files\n# 'gts' should map image_id to a list of ground truth captions\n# 'res' should map image_id to a list of predicted captions\n\ngts_data = {\n    \"annotations\": [\n        {\"image_id\": 1, \"id\": 101, \"caption\": \"A man is riding a bicycle.\"}, \n        {\"image_id\": 1, \"id\": 102, \"caption\": \"A person on a bike on a street.\"}, \n        {\"image_id\": 2, \"id\": 201, \"caption\": \"Two dogs playing in the grass.\"}, \n        {\"image_id\": 2, \"id\": 202, \"caption\": \"Dogs are running on a lawn.\"}\n    ]\n}\n\nres_data = [\n    {\"image_id\": 1, \"caption\": \"A man cycling on a road.\", \"id\": 301}, \n    {\"image_id\": 2, \"caption\": \"Two puppies in a field.\", \"id\": 302}\n]\n\n# To initialize COCOEvalCap, you need COCO objects for ground truth and results.\n# These COCO objects are typically created from JSON files matching the COCO format.\n# For a quickstart, we'll manually structure the data to match expected input.\n\n# The COCO object expects a dictionary with 'images' and 'annotations' keys.\n# We only need 'annotations' for caption evaluation.\n\n# Mock COCO objects (simplified for quickstart, actual COCO objects handle more fields)\nclass MockCoco:\n    def __init__(self, data):\n        self.anns = {ann['id']: ann for ann in data.get('annotations', [])}\n        self.imgToAnns = {}\n        for ann in data.get('annotations', []):\n            self.imgToAnns.setdefault(ann['image_id'], []).append(ann)\n\n    def loadRes(self, res_json_or_list):\n        # For simplicity, just store results. COCO.loadRes is more complex.\n        res_anns = []\n        for r in res_json_or_list:\n            # Assign a unique ID if not present, similar to COCO API behavior\n            if 'id' not in r:\n                r['id'] = max(self.anns.keys(), default=0) + len(res_anns) + 1\n            res_anns.append(r)\n        res_coco = MockCoco({'annotations': res_anns})\n        return res_coco\n\n    def getImgIds(self):\n        return list(self.imgToAnns.keys())\n\n    def loadAnns(self, ids):\n        return [self.anns[i] for i in ids]\n\n# Initialize Mock COCO objects\n# gts_coco_obj = COCO(gts_json_path)  # In a real application\ngts_coco_obj = MockCoco(gts_data)\n\n# res_coco_obj = gts_coco_obj.loadRes(res_json_path) # In a real application\nres_coco_obj = gts_coco_obj.loadRes(res_data)\n\neval_ids = gts_coco_obj.getImgIds()\n\ncocoEval = COCOEvalCap(gts_coco_obj, res_coco_obj, eval_ids)\n\ncocoEval.evaluate()\n\nprint(\"Evaluation results:\")\nfor metric, score in cocoEval.eval.items():\n    print(f\"{metric}: {score:.3f}\")","lang":"python","description":"This quickstart demonstrates how to set up and run the evaluation using `COCOEvalCap`. It uses mocked ground truth and predicted caption data to illustrate the expected data structure. In a real application, you would load your ground truth annotations into a `pycocotools.coco.COCO` object and your prediction results into another `COCO` object (using `loadRes`). The `evaluate()` method then computes all standard metrics.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"1.2","pypi_latest":"1.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":5.1,"avg_import_s":0.44,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.37,"mem_mb":11,"disk_size":"191.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.8,"import_time_s":0.3,"mem_mb":11,"disk_size":"188M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.59,"mem_mb":12.2,"disk_size":"198.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.8,"import_time_s":0.5,"mem_mb":12.2,"disk_size":"195M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.47,"mem_mb":12,"disk_size":"187.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.7,"import_time_s":0.53,"mem_mb":12,"disk_size":"183M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.45,"mem_mb":13,"disk_size":"186.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.9,"import_time_s":0.48,"mem_mb":13,"disk_size":"182M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.37,"mem_mb":10.5,"disk_size":"199.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pycocoevalcap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":6.1,"import_time_s":0.35,"mem_mb":10.5,"disk_size":"198M"}]}}