{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"总感觉验证的时候算mAP有问题。为了看看问题出在哪，我拿了两张图出来，把预测结果直接替换成已知的bbox （debug_pred.json），理论上mAP得为1。但两张图分开算但时候是1，放一起评估却出了问题，网上搜了一圈也没意识到问题在哪。","metadata":{}},{"cell_type":"code","source":"import os, json\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-03T21:03:08.012258Z","iopub.execute_input":"2021-08-03T21:03:08.012661Z","iopub.status.idle":"2021-08-03T21:03:08.017168Z","shell.execute_reply.started":"2021-08-03T21:03:08.012627Z","shell.execute_reply":"2021-08-03T21:03:08.016387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pycocotools\nfrom pycocotools.coco import COCO\nfrom pycocotools.cocoeval import COCOeval","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:01:22.326660Z","iopub.execute_input":"2021-08-03T21:01:22.327311Z","iopub.status.idle":"2021-08-03T21:01:40.070481Z","shell.execute_reply.started":"2021-08-03T21:01:22.327203Z","shell.execute_reply":"2021-08-03T21:01:40.069128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_dir = '../input/debug-coco'","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:02:33.135205Z","iopub.execute_input":"2021-08-03T21:02:33.135584Z","iopub.status.idle":"2021-08-03T21:02:33.140182Z","shell.execute_reply.started":"2021-08-03T21:02:33.135539Z","shell.execute_reply":"2021-08-03T21:02:33.139206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"coco_gt = COCO(os.path.join(input_dir,'debug.json'))\ncoco_dt = coco_gt.loadRes(os.path.join(input_dir,'debug_pred.json'))","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:03:13.421934Z","iopub.execute_input":"2021-08-03T21:03:13.422546Z","iopub.status.idle":"2021-08-03T21:03:13.441414Z","shell.execute_reply.started":"2021-08-03T21:03:13.422512Z","shell.execute_reply":"2021-08-03T21:03:13.440390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgIds = coco_gt.getImgIds()\nimgIds","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:03:29.470525Z","iopub.execute_input":"2021-08-03T21:03:29.470917Z","iopub.status.idle":"2021-08-03T21:03:29.584277Z","shell.execute_reply.started":"2021-08-03T21:03:29.470885Z","shell.execute_reply":"2021-08-03T21:03:29.583019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cocoEval = COCOeval(coco_gt,coco_dt,'bbox')\ncocoEval.params.imgIds = imgIds[0]\ncocoEval.evaluate()\ncocoEval.accumulate()\ncocoEval.summarize()","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:03:47.537352Z","iopub.execute_input":"2021-08-03T21:03:47.537768Z","iopub.status.idle":"2021-08-03T21:03:47.561771Z","shell.execute_reply.started":"2021-08-03T21:03:47.537737Z","shell.execute_reply":"2021-08-03T21:03:47.560733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cocoEval = COCOeval(coco_gt,coco_dt,'bbox')\ncocoEval.params.imgIds = imgIds[1]\ncocoEval.evaluate()\ncocoEval.accumulate()\ncocoEval.summarize()","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:03:58.680613Z","iopub.execute_input":"2021-08-03T21:03:58.680964Z","iopub.status.idle":"2021-08-03T21:03:58.703851Z","shell.execute_reply.started":"2021-08-03T21:03:58.680935Z","shell.execute_reply":"2021-08-03T21:03:58.702758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cocoEval = COCOeval(coco_gt,coco_dt,'bbox')\ncocoEval.params.imgIds = imgIds\ncocoEval.evaluate()\ncocoEval.accumulate()\ncocoEval.summarize()","metadata":{"execution":{"iopub.status.busy":"2021-08-03T21:04:07.270263Z","iopub.execute_input":"2021-08-03T21:04:07.270660Z","iopub.status.idle":"2021-08-03T21:04:07.280738Z","shell.execute_reply.started":"2021-08-03T21:04:07.270628Z","shell.execute_reply":"2021-08-03T21:04:07.279690Z"},"trusted":true},"execution_count":null,"outputs":[]}]}