{ "cells": [ { "cell_type": "markdown", "id": "263c13a6", "metadata": {}, "source": [ "# Simple eval example" ] }, { "cell_type": "code", "execution_count": 1, "id": "9c4a7668-aede-4f8c-833a-bf6eedc489e7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "faster_coco_eval.__version__='1.6.6'\n" ] } ], "source": [ "import json\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, "id": "a28dde2b-7219-4d9c-acbe-0e4d9db05692", "metadata": {}, "outputs": [], "source": [ "prepared_coco_in_dict = COCO.load_json(\"../tests/dataset/gt_dataset.json\")\n", "prepared_anns = COCO.load_json(\"../tests/dataset/dt_dataset.json\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "22132ee6-11c0-4c43-8f08-cf5729cd4727", "metadata": {}, "outputs": [], "source": [ "iouType = \"segm\"\n", "useCats = False" ] }, { "cell_type": "code", "execution_count": 4, "id": "1539cfd1-e76c-45bb-91b2-b3afa52eec68", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:faster_coco_eval.core.cocoeval:Evaluate annotation type *segm*\n", "INFO:faster_coco_eval.core.cocoeval:COCOeval_opt.evaluate() finished...\n", "INFO:faster_coco_eval.core.cocoeval:DONE (t=0.00s).\n", "INFO:faster_coco_eval.core.cocoeval:Accumulating evaluation results...\n", "INFO:faster_coco_eval.core.cocoeval:COCOeval_opt.accumulate() finished...\n", "INFO:faster_coco_eval.core.cocoeval:DONE (t=0.00s).\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets= 9 ] = 0.783\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.50 | area= all | maxDets= 9 ] = 0.783\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.75 | area= all | maxDets= 9 ] = 0.783\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets= 9 ] = -1.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets= 9 ] = 1.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets= 9 ] = 0.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 9 ] = 0.889\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets= 9 ] = -1.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets= 9 ] = 1.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets= 9 ] = 0.000\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.50 | area= all | maxDets= 9 ] = 0.889\n", "INFO:faster_coco_eval.core.cocoeval: Average Recall (AR) @[ IoU=0.75 | area= all | maxDets= 9 ] = 0.889\n" ] } ], "source": [ "cocoGt = COCO(prepared_coco_in_dict)\n", "cocoDt = cocoGt.loadRes(prepared_anns)\n", "\n", "cocoEval = COCOeval_faster(cocoGt, cocoDt, iouType, extra_calc=True)\n", "cocoEval.params.maxDets = [len(cocoGt.anns)]\n", "\n", "if not useCats:\n", " cocoEval.params.useCats = 0 # Выключение labels\n", "\n", "cocoEval.evaluate()\n", "cocoEval.accumulate()\n", "cocoEval.summarize()" ] }, { "cell_type": "code", "execution_count": 5, "id": "6990cc70-10aa-4f08-bfe7-9d23d6a28cb6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0.78327833, 0.78327833, 0.78327833, -1. , 1. ,\n", " 0. , 0.88888889, 0. , 0. , -1. ,\n", " 1. , 0. ])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocoEval.stats" ] }, { "cell_type": "code", "execution_count": 6, "id": "587b3440-9c35-4363-a89f-9d485084f9fe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'AP_all': 0.7832783278327835,\n", " 'AP_50': 0.7832783278327836,\n", " 'AP_75': 0.7832783278327836,\n", " 'AP_small': -1.0,\n", " 'AP_medium': 1.0,\n", " 'AP_large': 0.0,\n", " 'AR_all': 0.888888888888889,\n", " 'AR_second': 0.0,\n", " 'AR_third': 0.0,\n", " 'AR_small': -1.0,\n", " 'AR_medium': 1.0,\n", " 'AR_large': 0.0,\n", " 'AR_50': 0.8888888888888888,\n", " 'AR_75': 0.8888888888888888,\n", " 'mIoU': 1.0,\n", " 'mAUC_50': 0.594074074074074}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocoEval.stats_as_dict" ] }, { "cell_type": "code", "execution_count": 7, "id": "75447bee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class_map': [{'class': 'all',\n", " 'map@50:95': 0.7832783278327835,\n", " 'map@50': 0.7832783278327836,\n", " 'precision': 0.8888888888888888,\n", " 'recall': 0.88}],\n", " 'map': 0.7832783278327836,\n", " 'precision': 0.8888888888888888,\n", " 'recall': 0.88}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocoEval.extended_metrics" ] } ], "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": 5 }