atom-predict/msunet/Metrics_.ipynb

250 lines
6.3 KiB
Plaintext
Executable File

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1e532855-9e9d-4839-8a5b-80ef9fc1f496",
"metadata": {},
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name 'get_mask' from 'utils.labelme' (/home/andrewtal/Workspace/metrials/atom/code/msunet/utils/labelme.py)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 9\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtqdm\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m tqdm\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmultiprocessing\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Pool\n\u001b[0;32m----> 9\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mutils\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mlabelme\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m get_mask\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mutils\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01me2e_metrics\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m get_metrics\n",
"\u001b[0;31mImportError\u001b[0m: cannot import name 'get_mask' from 'utils.labelme' (/home/andrewtal/Workspace/metrials/atom/code/msunet/utils/labelme.py)"
]
}
],
"source": [
"import json\n",
"import glob\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from tqdm import tqdm\n",
"from multiprocessing import Pool\n",
"\n",
"from utils.labelme import get_mask\n",
"from utils.e2e_metrics import get_metrics"
]
},
{
"cell_type": "markdown",
"id": "83c85338-5689-45f1-8286-51ff697aa04a",
"metadata": {},
"source": [
"# metrics"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "79e3c40d-6ac2-41da-a3b1-a25c6bc6f1e4",
"metadata": {},
"outputs": [],
"source": [
"def get_score():\n",
" res = []\n",
"\n",
" for id in range(nums):\n",
" res += [get_metrics(\n",
" label[id], \n",
" get_mask(pred[id], min_size=4)\n",
" )]\n",
" \n",
" return res"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dfae81e3-1287-48d0-913f-c39542b689b7",
"metadata": {},
"outputs": [],
"source": [
"def get_score_v():\n",
" res = []\n",
"\n",
" for id in range(nums):\n",
" res += [get_metrics(\n",
" np.array(label[id] > 1),\n",
" get_mask(pred[id], min_size=4)\n",
" )]\n",
" \n",
" return res"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "cc070f47-9910-436a-a1dc-49c48bbbc41e",
"metadata": {},
"outputs": [],
"source": [
"with open('./logs/0/version_0/result.json') as f:\n",
" data = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "31f61d06-34c5-4595-883b-b240304993f0",
"metadata": {},
"outputs": [],
"source": [
"img_path = np.array(data['img_path'])\n",
"metric_idx = np.array([item.split('/')[-1].split('.')[0] not in ['4', '8'] for item in img_path])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ebeb8904-4125-4709-a88b-7ef8c3d4a482",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"label = np.array(data['label']) # [metric_idx]\n",
"pred = np.array(data['pred']) # [metric_idx]\n",
"\n",
"nums = label.shape[0]; nums"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a94f789b-8ec9-4637-a523-1ea93e183eb5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.99447763, 0.995673 , 0.99507427])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.mean(get_score(), axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "3ab02e37-ee18-496b-98ca-155432178551",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.08341605, 0.97570966, 0.15249978])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.mean(get_score_v(), axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "40ea70e0-0bdb-4c17-adc6-a2c492d1d842",
"metadata": {},
"outputs": [],
"source": [
"# array([0.99489517, 0.99558528, 0.99523956])\n",
"# array([0.08338148, 0.97506031, 0.15243086])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a91a73ae-96c3-49e0-acd7-fde7d8138998",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5534b4ac-5726-49ee-a5f1-17a3be7eed30",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4338b46-d62a-4867-868d-96b9056935de",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b092391-cad2-4ce8-a9e3-556a0b95d64b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f4f3a57-35fa-41a1-b3cc-e2cef8e94ce7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5189ddc5-e955-47bd-9b6c-7ecb4fa75520",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "cmae",
"language": "python",
"name": "cmae"
},
"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.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}