{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "faster_coco_eval.__version__='1.5.6'\n" ] } ], "source": [ "import numpy as np\n", "import logging\n", "import faster_coco_eval\n", "from faster_coco_eval import COCO, COCOeval_faster\n", "\n", "print(f\"{faster_coco_eval.__version__=}\")\n", "\n", "logging.root.setLevel(\"INFO\")\n", "logging.debug(\"Запись.\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "prepared_coco_in_dict = COCO.load_json(\"../tests/lvis_dataset/lvis_val_100.json\")\n", "prepared_anns = COCO.load_json(\"../tests/lvis_dataset/lvis_results_100.json\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "iouType = \"bbox\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:lvis.lvis:Loading annotations.\n", "INFO:lvis.lvis:Creating index.\n", "INFO:lvis.lvis:Index created.\n", "INFO:lvis.results:Loading and preparing results.\n", "INFO:lvis.results:Creating index.\n", "INFO:lvis.results:Index created.\n" ] } ], "source": [ "from lvis import LVISEval\n", "\n", "lvis_eval = LVISEval(\"../tests/lvis_dataset/lvis_val_100.json\", \"../tests/lvis_dataset/lvis_results_100.json\", iouType)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:lvis.eval:Running per image evaluation.\n", "INFO:lvis.eval:Evaluate annotation type *bbox*\n", "INFO:lvis.eval:COCOeval_opt._prepare() finished...\n", "INFO:lvis.eval:DONE (t=0.01s).\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 766 ms, sys: 32 ms, total: 798 ms\n", "Wall time: 794 ms\n" ] } ], "source": [ "%%time\n", "\n", "lvis_eval.evaluate()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:lvis.eval:Accumulating evaluation results.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 111 ms, sys: 2.12 ms, total: 114 ms\n", "Wall time: 113 ms\n" ] } ], "source": [ "%%time\n", "\n", "lvis_eval.accumulate()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 22.5 ms, sys: 21.4 ms, total: 43.8 ms\n", "Wall time: 42.8 ms\n" ] } ], "source": [ "%%time\n", "\n", "lvis_eval.summarize()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.368\n", " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.626\n", " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.384\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= s | maxDets=300 catIds=all] = 0.301\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= m | maxDets=300 catIds=all] = 0.438\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= l | maxDets=300 catIds=all] = 0.447\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= r] = 0.000\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= c] = 0.274\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= f] = 0.388\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.430\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= s | maxDets=300 catIds=all] = 0.345\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= m | maxDets=300 catIds=all] = 0.488\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= l | maxDets=300 catIds=all] = 0.515\n" ] } ], "source": [ "lvis_eval.print_results()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "cocoGt = COCO(prepared_coco_in_dict)\n", "cocoDt = cocoGt.loadRes(prepared_anns)\n", "\n", "cocoEval = COCOeval_faster(cocoGt, cocoDt, iouType, lvis_style=True, print_function=print)\n", "cocoEval.params.maxDets = [300]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Evaluate annotation type *bbox*\n", "COCOeval_opt._prepare() finished...\n", "DONE (t=0.01s).\n", "COCOeval_opt.evaluate() finished...\n", "DONE (t=0.63s).\n", "CPU times: user 581 ms, sys: 53.2 ms, total: 634 ms\n", "Wall time: 631 ms\n" ] } ], "source": [ "%%time\n", "\n", "cocoEval.evaluate()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accumulating evaluation results...\n", "COCOeval_opt.accumulate() finished...\n", "DONE (t=0.00s).\n", "CPU times: user 42 µs, sys: 20 µs, total: 62 µs\n", "Wall time: 59.6 µs\n" ] } ], "source": [ "%%time\n", "\n", "cocoEval.accumulate()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.368\n", " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.626\n", " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.384\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.301\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.438\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.447\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= r] = 0.000\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= c] = 0.274\n", " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= f] = 0.388\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.430\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.345\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.488\n", " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.515\n", " Average Recall (AR) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.720\n", " Average Recall (AR) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.445\n", "CPU times: user 31.7 ms, sys: 8.7 ms, total: 40.4 ms\n", "Wall time: 39.5 ms\n" ] } ], "source": [ "%%time\n", "\n", "cocoEval.summarize()" ] } ], "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.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }