: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)
| 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 + '/brats2020/MICCAI_BraTS_2020_Data_Training/' |
| 32 | self.testing_path = self.root + '/brats2020/MICCAI_BraTS_2020_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 + '/brats2020/brats2020-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 + '/brats2020/generated/' + mode + subvol + '/' |
| 57 | utils.make_dirs(self.sub_vol_path) |
| 58 | |
| 59 | list_IDsT1 = sorted(glob.glob(os.path.join(self.training_path, '*/*t1.nii.gz'))) |
| 60 | list_IDsT1ce = sorted(glob.glob(os.path.join(self.training_path, '*/*t1ce.nii.gz'))) |
| 61 | list_IDsT2 = sorted(glob.glob(os.path.join(self.training_path, '*/*t2.nii.gz'))) |
| 62 | list_IDsFlair = sorted(glob.glob(os.path.join(self.training_path, '*/*_flair.nii.gz'))) |
| 63 | labels = sorted(glob.glob(os.path.join(self.training_path, '*/*_seg.nii.gz'))) |
| 64 | |
| 65 | list_IDsT1, list_IDsT1ce, list_IDsT2, list_IDsFlair, labels = utils.shuffle_lists(list_IDsT1, list_IDsT1ce, |
| 66 | list_IDsT2, |
| 67 | list_IDsFlair, labels, |
| 68 | seed=17) |
| 69 | assert len(list_IDsT1) == len(list_IDsT2) == len(list_IDsT1ce) == len(list_IDsFlair) |
| 70 | self.affine = img_loader.load_affine_matrix(list_IDsT1[0]) |
| 71 | |
| 72 | if self.mode == 'train': |
| 73 | print('Brats2020, Total data:', len(list_IDsT1)) |
| 74 | list_IDsT1 = list_IDsT1[:split_idx] |
| 75 | list_IDsT1ce = list_IDsT1ce[:split_idx] |
| 76 | list_IDsT2 = list_IDsT2[:split_idx] |
nothing calls this directly
no test coverage detected