Created
December 19, 2019 23:56
-
-
Save botcs/d37e1df05cbabcd6b76f6b0232523dd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import json\n", | |
| "from pycocotools.coco import COCO\n", | |
| "from pycocotools.cocoeval import COCOeval\n", | |
| "from copy import deepcopy" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "orig_gt_path = \"/home/botoscs/data/MS-COCO/annotations/instances_minival2014.json\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "gt = json.load(open(orig_gt_path))\n", | |
| "\n", | |
| "gt[\"annotations\"][:] = gt[\"annotations\"][:1]\n", | |
| "del gt[\"annotations\"][0][\"segmentation\"]\n", | |
| "\n", | |
| "pred = deepcopy(gt)\n", | |
| "pred[\"annotations\"][0][\"score\"] = 1.0\n", | |
| "\n", | |
| "# Duplicate the detections for the very same object\n", | |
| "pred[\"annotations\"] += pred[\"annotations\"]\n", | |
| "pred = pred[\"annotations\"]\n", | |
| "\n", | |
| "json.dump(gt, open(\"gt.json\", \"w\"))\n", | |
| "json.dump(pred, open(\"pred.json\", \"w\"))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[{'area': 702.10575,\n", | |
| " 'iscrowd': 0,\n", | |
| " 'image_id': 289343,\n", | |
| " 'bbox': [473.07, 395.93, 38.65, 28.67],\n", | |
| " 'category_id': 18,\n", | |
| " 'id': 1768}]" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "gt[\"annotations\"]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[{'area': 702.10575,\n", | |
| " 'iscrowd': 0,\n", | |
| " 'image_id': 289343,\n", | |
| " 'bbox': [473.07, 395.93, 38.65, 28.67],\n", | |
| " 'category_id': 18,\n", | |
| " 'id': 1768,\n", | |
| " 'score': 1.0},\n", | |
| " {'area': 702.10575,\n", | |
| " 'iscrowd': 0,\n", | |
| " 'image_id': 289343,\n", | |
| " 'bbox': [473.07, 395.93, 38.65, 28.67],\n", | |
| " 'category_id': 18,\n", | |
| " 'id': 1768,\n", | |
| " 'score': 1.0}]" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "pred" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "loading annotations into memory...\n", | |
| "Done (t=0.02s)\n", | |
| "creating index...\n", | |
| "index created!\n", | |
| "Loading and preparing results...\n", | |
| "DONE (t=0.00s)\n", | |
| "creating index...\n", | |
| "index created!\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "cocoGt = COCO(\"gt.json\")\n", | |
| "cocoDt = cocoGt.loadRes(\"pred.json\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Running per image evaluation...\n", | |
| "Evaluate annotation type *bbox*\n", | |
| "DONE (t=3.14s).\n", | |
| "Accumulating evaluation results...\n", | |
| "DONE (t=0.52s).\n", | |
| " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 1.000\n", | |
| " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 1.000\n", | |
| " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 1.000\n", | |
| " Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 1.000\n", | |
| " Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000\n", | |
| " Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000\n", | |
| " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "cocoEval = COCOeval(cocoGt,cocoDt,\"bbox\")\n", | |
| "cocoEval.evaluate()\n", | |
| "cocoEval.accumulate()\n", | |
| "cocoEval.summarize()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.7.5" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment