{ "cells": [ { "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.4.2'\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": "9a6c7b67-616b-4feb-9f1d-9dcbb384ed2c", "metadata": {}, "outputs": [], "source": [ "def load(file):\n", " with open(file) as io:\n", " _data = json.load(io)\n", "\n", " return _data" ] }, { "cell_type": "code", "execution_count": 3, "id": "a28dde2b-7219-4d9c-acbe-0e4d9db05692", "metadata": {}, "outputs": [], "source": [ "prepared_coco_in_dict = load(\"../tests/dataset/gt_dataset.json\")\n", "prepared_anns = load(\"../tests/dataset/dt_dataset.json\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "22132ee6-11c0-4c43-8f08-cf5729cd4727", "metadata": {}, "outputs": [], "source": [ "iouType = \"segm\"\n", "useCats = False" ] }, { "cell_type": "code", "execution_count": 5, "id": "1539cfd1-e76c-45bb-91b2-b3afa52eec68", "metadata": {}, "outputs": [], "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": 6, "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": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocoEval.stats" ] }, { "cell_type": "code", "execution_count": 7, "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": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocoEval.stats_as_dict" ] } ], "metadata": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" }, "kernelspec": { "display_name": "Python 3.9.5 64-bit", "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 }