MCPcopy
hub / github.com/black0017/MedicalZooPytorch / __init__

Method __init__

lib/medloaders/brats2019.py:19–100  ·  view source on GitHub ↗

:param mode: 'train','val','test' :param dataset_path: root dataset folder :param crop_dim: subvolume tuple :param split_idx: 1 to 10 values :param samples: number of sub-volumes that you want to create

(self, args, mode, dataset_path='./datasets', classes=5, crop_dim=(200, 200, 150), split_idx=260,
                 samples=10,
                 load=False)

Source from the content-addressed store, hash-verified

17 """
18
19 def __init__(self, args, mode, dataset_path='./datasets', classes=5, crop_dim=(200, 200, 150), split_idx=260,
20 samples=10,
21 load=False):
22 """
23 :param mode: 'train','val','test'
24 :param dataset_path: root dataset folder
25 :param crop_dim: subvolume tuple
26 :param split_idx: 1 to 10 values
27 :param samples: number of sub-volumes that you want to create
28 """
29 self.mode = mode
30 self.root = str(dataset_path)
31 self.training_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/'
32 self.testing_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Validation/'
33 self.full_vol_dim = (240, 240, 155) # slice, width, height
34 self.crop_size = crop_dim
35 self.threshold = args.threshold
36 self.normalization = args.normalization
37 self.augmentation = args.augmentation
38 self.list = []
39 self.samples = samples
40 self.full_volume = None
41 self.classes = classes
42 if self.augmentation:
43 self.transform = augment3D.RandomChoice(
44 transforms=[augment3D.GaussianNoise(mean=0, std=0.01), augment3D.RandomFlip(),
45 augment3D.ElasticTransform()], p=0.5)
46 self.save_name = self.root + '/brats2019/brats2019-list-' + mode + '-samples-' + str(samples) + '.txt'
47
48 if load:
49 ## load pre-generated data
50 self.list = utils.load_list(self.save_name)
51 list_IDsT1 = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*t1.nii.gz')))
52 self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
53 return
54
55 subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(crop_dim[1]) + 'x' + str(crop_dim[2])
56 self.sub_vol_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/generated/' + mode + subvol + '/'
57 utils.make_dirs(self.sub_vol_path)
58
59 list_IDsT1 = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*t1.nii.gz')))
60 list_IDsT1ce = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*t1ce.nii.gz')))
61 list_IDsT2 = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*t2.nii.gz')))
62 list_IDsFlair = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*_flair.nii.gz')))
63 labels = sorted(glob.glob(os.path.join(self.training_path, '*GG/*/*_seg.nii.gz')))
64 list_IDsT1, list_IDsT1ce, list_IDsT2, list_IDsFlair, labels = utils.shuffle_lists(list_IDsT1, list_IDsT1ce,
65 list_IDsT2,
66 list_IDsFlair, labels,
67 seed=17)
68 self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
69
70 if self.mode == 'train':
71 print('Brats2019, Total data:', len(list_IDsT1))
72 list_IDsT1 = list_IDsT1[:split_idx]
73 list_IDsT1ce = list_IDsT1ce[:split_idx]
74 list_IDsT2 = list_IDsT2[:split_idx]
75 list_IDsFlair = list_IDsFlair[:split_idx]
76 labels = labels[:split_idx]

Callers

nothing calls this directly

Calls 1

create_sub_volumesFunction · 0.90

Tested by

no test coverage detected