Skip to content

Commit

Permalink
add evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzjalen committed May 28, 2024
1 parent ca04ab1 commit 6192877
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 29 deletions.
2 changes: 1 addition & 1 deletion scripts/del_npy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import os\n",
"\n",
"dir = \"/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_preprocessed/Dataset101_mosaic_skelet_spine/nnUNetPlans_3d_fullres\"\n",
"dir = \"/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_preprocessed/Dataset300_mosaic_cardiovascular/nnUNetPlans_3d_fullres\"\n",
"files = os.listdir(dir)\n",
"\n",
"for file in files:\n",
Expand Down
63 changes: 63 additions & 0 deletions scripts/evaluate.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from nnunetv2.evaluation.evaluate_predictions import compute_metrics_on_folder, labels_to_list_of_regions\n",
"from nnunetv2.imageio.nibabel_reader_writer import NibabelIOWithReorient\n",
"import json\n",
"\n",
"folder_ref = '/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_raw/Dataset300_mosaic_cardiovascular/labelsTr'\n",
"model_folder = '/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_results/Dataset300_mosaic_cardiovascular/nnUNetTrainer_1500epochs_NoMirroring__Mosaic_nnUNetPlannerResEncL_stdres_NoRsmp_24G__3d_fullres'\n",
"folder_pred = f'{model_folder}/fold_0/validation'\n",
"output_file = f'{folder_pred}/summary.json'\n",
"dataset_json = f'{model_folder}/dataset.json'\n",
"image_reader_writer = NibabelIOWithReorient()\n",
"file_ending = '.nii.gz'\n",
"ignore_label = None\n",
"num_processes = 12\n",
"\n",
"with open(dataset_json) as f:\n",
" data = json.loads(f.read())\n",
"\n",
"# regions = labels_to_list_of_regions(list(data['labels'].values())[1:])\n",
"\n",
"regions = list(data['labels'].values())[1:]\n",
"\n",
"compute_metrics_on_folder(folder_ref, folder_pred, output_file, image_reader_writer, file_ending, regions, ignore_label,\n",
" num_processes)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".nnunetv2-venv",
"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
}
54 changes: 26 additions & 28 deletions scripts/generate_json.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,44 @@
"from nnunetv2.dataset_conversion.generate_dataset_json import generate_dataset_json\n",
"import os\n",
"\n",
"dataset = \"/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_raw/Dataset101_mosaic_skelet_ribs\"\n",
"dataset = \"/home/eolika/Desktop/BlueMind/nnUNet/trains/nnUNet_raw/Dataset300_mosaic_cardiovascular\"\n",
"\n",
"generate_dataset_json(output_folder=dataset,\n",
" channel_names={0: \"CT\"},\n",
" labels={\n",
" 'background': 0,\n",
" \"rib_left_1\": 1,\n",
" \"rib_left_2\": 2,\n",
" \"rib_left_3\": 3,\n",
" \"rib_left_4\": 4,\n",
" \"rib_left_5\": 5,\n",
" \"rib_left_6\": 6,\n",
" \"rib_left_7\": 7,\n",
" \"rib_left_8\": 8,\n",
" \"rib_left_9\": 9,\n",
" \"rib_left_10\": 10,\n",
" \"rib_left_11\": 11,\n",
" \"rib_left_12\": 12,\n",
" \"rib_right_1\": 13,\n",
" \"rib_right_2\": 14,\n",
" \"rib_right_3\": 15,\n",
" \"rib_right_4\": 16,\n",
" \"rib_right_5\": 17,\n",
" \"rib_right_6\": 18,\n",
" \"rib_right_7\": 19,\n",
" \"rib_right_8\": 20,\n",
" \"rib_right_9\": 21,\n",
" \"rib_right_10\": 22,\n",
" \"rib_right_11\": 23,\n",
" \"rib_right_12\": 24,\n",
" \"costal_cartilages\": 25,\n",
" \"sternum\": 26\n",
" \"heart_myocardium\": 1,\n",
" \"heart_atrium_left\": 2,\n",
" \"heart_ventricle_left\": 3,\n",
" \"heart_atrium_right\": 4,\n",
" \"heart_ventricle_right\": 5,\n",
" \"aorta\": 6,\n",
" \"pulmonary_vein\": 7,\n",
" \"pulmonary_artery\": 8,\n",
" \"brachiocephalic_trunk\": 9,\n",
" \"subclavian_artery_right\": 10,\n",
" \"subclavian_artery_left\": 11,\n",
" \"common_carotid_artery_right\": 12,\n",
" \"common_carotid_artery_left\": 13,\n",
" \"brachiocephalic_vein_left\": 14,\n",
" \"brachiocephalic_vein_right\": 15,\n",
" \"superior_vena_cava\": 16,\n",
" \"inferior_vena_cava\": 17,\n",
" \"portal_vein_and_splenic_vein\": 18,\n",
" \"iliac_artery_left\": 19,\n",
" \"iliac_artery_right\": 20,\n",
" \"iliac_vena_left\": 21,\n",
" \"iliac_vena_right\": 22,\n",
" \"liver_vessels\": 23,\n",
" \"lung_vessels\": 24\n",
" },\n",
" num_training_cases=len(os.listdir(f'{dataset}/imagesTr')), \n",
" file_ending='.nii.gz',\n",
" dataset_name=dataset.split('/')[-1], \n",
" reference='BlueMind AI Inc',\n",
" release='1.0.0',\n",
" overwrite_image_reader_writer='NibabelIOWithReorient',\n",
" description=\"skelet_ribs\")"
" description=\"cardiovascular\")"
]
},
{
Expand Down

0 comments on commit 6192877

Please sign in to comment.