Skip to content

Commit

Permalink
do not creaty npy if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzjalen committed Mar 13, 2024
1 parent 45b41fa commit 9859079
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
6 changes: 4 additions & 2 deletions nnunetv2/training/dataloading/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ def _convert_to_npy(npz_file: str, unpack_segmentation: bool = True, overwrite_e
try:
a = np.load(npz_file) # inexpensive, no compression is done here. This just reads metadata
if overwrite_existing or not isfile(npz_file[:-3] + "npy"):
np.save(npz_file[:-3] + "npy", a['data'])
if not os.path.exists(npz_file[:-3] + "npy"):
np.save(npz_file[:-3] + "npy", a['data'])
if unpack_segmentation and (overwrite_existing or not isfile(npz_file[:-4] + "_seg.npy")):
np.save(npz_file[:-4] + "_seg.npy", a['seg'])
if not os.path.exists(npz_file[:-4] + "_seg.npy"):
np.save(npz_file[:-4] + "_seg.npy", a['seg'])
except KeyboardInterrupt:
if isfile(npz_file[:-3] + "npy"):
os.remove(npz_file[:-3] + "npy")
Expand Down
38 changes: 12 additions & 26 deletions scripts/generate_json.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,30 @@
"from nnunetv2.dataset_conversion.generate_dataset_json import generate_dataset_json\n",
"import os\n",
"\n",
"dataset = \"/media/eolika/49755d50-5426-4672-87cc-2d1a5a3747ad/nnUNet/nnUNet_raw/Dataset103_mosaic_cardiovascular\"\n",
"dataset = \"/media/eolika/49755d50-5426-4672-87cc-2d1a5a3747ad/nnUNet/nnUNet_raw/Dataset102_mosaic_muscles\"\n",
"\n",
"generate_dataset_json(output_folder=dataset,\n",
" channel_names={0: \"CT\"},\n",
" labels={\n",
" \"background\": 0,\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",
" \"gluteus_maximus_left\": 1,\n",
" \"gluteus_maximus_right\": 2,\n",
" \"gluteus_medius_left\": 3,\n",
" \"gluteus_medius_right\": 4,\n",
" \"gluteus_minimus_left\": 5,\n",
" \"gluteus_minimus_right\": 6,\n",
" \"autochthon_left\": 7,\n",
" \"autochthon_right\": 8,\n",
" \"iliopsoas_left\": 9,\n",
" \"iliopsoas_right\": 10\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=\"cardiovascular\")"
" description=\"muscles\")"
]
},
{
Expand Down

0 comments on commit 9859079

Please sign in to comment.