Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samhughess committed Apr 28, 2024
1 parent 3551611 commit 1bab122
Show file tree
Hide file tree
Showing 14 changed files with 4,077 additions and 18 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified nnunetv2/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion nnunetv2/dataset_conversion/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"label": 0
},
"numTraining": 257,
"file_ending": ".json"
"file_ending": ".mha"
}
217 changes: 213 additions & 4 deletions nnunetv2/dataset_conversion/generate_dataset_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,218 @@ def generate_dataset_json(output_folder: str,
save_json(dataset_json, join(output_folder, 'dataset.json'), sort_keys=False)

output_folder = "/Users/samanthahughes/nnUNet/nnunetv2/nnuNet_raw/Dataset011_LS"
channel_names = {0: 'T1', 1:'CT'}
labels= {1: 0}
num_training_cases= 257
file_ending= "target"
channel_names = {0: 'T1'}
labels= {'background': 0,
'label1': 1,
'label2': 2,
'label3': 3,
'label4': 4,
'label5': 5,
'label6': 6,
'label7': 7,
'label8': 8,
'label9': 9,
'label10': 10,
'label11': 11,
'label12': 12,
'label13': 13,
'label14': 14,
'label15': 15,
'label16': 16,
'label17': 17,
'label18': 18,
'label19': 19,
'label20': 20,
'label21': 21,
'label22': 22,
'label23': 23,
'label24': 24,
'label25': 25,
'label26': 26,
'label27': 27,
'label28': 28,
'label29': 29,
'label30': 30,
'label31': 31,
'label32': 32,
'label33': 33,
'label34': 34,
'label35': 35,
'label36': 36,
'label37': 37,
'label38': 38,
'label39': 39,
'label40': 40,
'label41': 41,
'label42': 42,
'label43': 43,
'label44': 44,
'label45': 45,
'label46': 46,
'label47': 47,
'label48': 48,
'label49': 49,
'label50': 50,
'label51': 51,
'label52': 52,
'label53': 53,
'label54': 54,
'label55': 55,
'label56': 56,
'label57': 57,
'label58': 58,
'label59': 59,
'label60': 60,
'label61': 61,
'label62': 62,
'label63': 63,
'label64': 64,
'label65': 65,
'label66': 66,
'label67': 67,
'label68': 68,
'label69': 69,
'label70': 70,
'label71': 71,
'label72': 72,
'label73': 73,
'label74': 74,
'label75': 75,
'label76': 76,
'label77': 77,
'label78': 78,
'label79': 79,
'label80': 80,
'label81': 81,
'label82': 82,
'label83': 83,
'label84': 84,
'label85': 85,
'label86': 86,
'label87': 87,
'label88': 88,
'label89': 89,
'label90': 90,
'label91': 91,
'label92': 92,
'label93': 93,
'label94': 94,
'label95': 95,
'label96': 96,
'label97': 97,
'label98': 98,
'label99': 99,
'label100': 100,
'label101': 101,
'label102': 102,
'label103': 103,
'label104': 104,
'label105': 105,
'label106': 106,
'label107': 107,
'label108': 108,
'label109': 109,
'label110': 110,
'label111': 111,
'label112': 112,
'label113': 113,
'label114': 114,
'label115': 115,
'label116': 116,
'label117': 117,
'label118': 118,
'label119': 119,
'label120': 120,
'label121': 121,
'label122': 122,
'label123': 123,
'label124': 124,
'label125': 125,
'label126': 126,
'label127': 127,
'label128': 128,
'label129': 129,
'label130': 130,
'label131': 131,
'label132': 132,
'label133': 133,
'label134': 134,
'label135': 135,
'label136': 136,
'label137': 137,
'label138': 138,
'label139': 139,
'label140': 140,
'label141': 141,
'label142': 142,
'label143': 143,
'label144': 144,
'label145': 145,
'label146': 146,
'label147': 147,
'label148': 148,
'label149': 149,
'label150': 150,
'label151': 151,
'label152': 152,
'label153': 153,
'label154': 154,
'label155': 155,
'label156': 156,
'label157': 157,
'label158': 158,
'label159': 159,
'label160': 160,
'label161': 161,
'label162': 162,
'label163': 163,
'label164': 164,
'label165': 165,
'label166': 166,
'label167': 167,
'label168': 168,
'label169': 169,
'label170': 170,
'label171': 171,
'label172': 172,
'label173': 173,
'label174': 174,
'label175': 175,
'label176': 176,
'label177': 177,
'label178': 178,
'label179': 179,
'label180': 180,
'label181': 181,
'label182': 182,
'label183': 183,
'label184': 184,
'label185': 185,
'label186': 186,
'label187': 187,
'label188': 188,
'label189': 189,
'label190': 190,
'label191': 191,
'label192': 192,
'label193': 193,
'label194': 194,
'label195': 195,
'label196': 196,
'label197': 197,
'label198': 198,
'label199': 199,
'label200': 200,
'label201': 201,
'label202': 202,
'label203': 203,
'label204': 204,
'label205': 205,
'label206': 206,
'label207': 207,
'label208':208,
'label209':209}
num_training_cases= 360
file_ending= ".mha"

generate_dataset_json(output_folder, channel_names, labels, num_training_cases, file_ending)
25 changes: 17 additions & 8 deletions nnunetv2/dataset_conversion/type_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,28 @@
validation.append(id)


source_dir = '/Users/samanthahughes/nnUNet/nnunetv2/nnuNet_raw/Dataset011_LS/labelsTr'
source_dir = '/Users/samanthahughes/nnUNet/nnunetv2/nnuNet_raw/Dataset011_LS/masks'
base_dir = '/Users/samanthahughes/nnUNet/nnunetv2/nnuNet_raw/Dataset011_LS/labelsTr'
other = '/Users/samanthahughes/nnUNet/nnunetv2/nnuNet_raw/Dataset012_target/labelsTr'

files = [f for f in os.listdir(source_dir) if os.path.isfile(os.path.join(source_dir, f))]
print(files)
f2 = [f for f in os.listdir(base_dir) if os.path.isfile(os.path.join(base_dir, f))]
print(len(f2), len(files))
test = []
test2 = []
for file in files:
name, extension = file.split('.')
print(extension)
if name not in validation:
continue
new_dir = os.path.join(base_dir, 'source')
os.makedirs(new_dir, exist_ok=True)
if name in training:
test.append(file)
shutil.move(os.path.join(source_dir, file), os.path.join(base_dir, file))
if name in validation:
test2.append(file)
shutil.move(os.path.join(source_dir, file), os.path.join(other, file))

shutil.move(os.path.join(source_dir, file), os.path.join(new_dir, file))
print(len(test), len(test2))
#new_dir = os.path.join(base_dir, 'source')
#os.makedirs(new_dir, exist_ok=True)

#shutil.move(os.path.join(source_dir, file), os.path.join(new_dir, file))

print("Files sorted by extension.")
3 changes: 2 additions & 1 deletion nnunetv2/evaluation/find_best_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


def filter_available_models(model_dict: Union[List[dict], Tuple[dict, ...]], dataset_name_or_id: Union[str, int]):
print(model_dict)
valid = []
for trained_model in model_dict:
plans_manager = PlansManager(join(nnUNet_preprocessed, maybe_convert_to_dataset_name(dataset_name_or_id),
Expand Down Expand Up @@ -325,7 +326,7 @@ def accumulate_crossval_results_entry_point():


if __name__ == '__main__':
find_best_configuration(4,
find_best_configuration(11,
default_trained_models,
True,
8,
Expand Down
3 changes: 2 additions & 1 deletion nnunetv2/imageio/nibabel_reader_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class NibabelIO(BaseReaderWriter):
supported_file_endings = [
'.nii.gz',
'.nrrd',
'.target'
'.target',
'.mha'
]

def read_images(self, image_fnames: Union[List[str], Tuple[str, ...]]) -> Tuple[np.ndarray, dict]:
Expand Down
1 change: 0 additions & 1 deletion nnunetv2/imageio/reader_writer_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
NibabelIOWithReorient
]


def determine_reader_writer_from_dataset_json(dataset_json_content: dict, example_file: str = None,
allow_nonmatching_filename: bool = False, verbose: bool = True
) -> Type[BaseReaderWriter]:
Expand Down
3 changes: 2 additions & 1 deletion nnunetv2/imageio/simpleitk_reader_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SimpleITKIO(BaseReaderWriter):
supported_file_endings = [
'.nii.gz',
'.nrrd',
'.target'
'.target',
'.mha'
]

def read_images(self, image_fnames: Union[List[str], Tuple[str, ...]]) -> Tuple[np.ndarray, dict]:
Expand Down
Binary file added nnunetv2/nnUNet_preprocessed/.DS_Store
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 1bab122

Please sign in to comment.