def __init__(self,
                 args,
                 mode,
                 dataset_path='../datasets',
                 classes=4,
                 dim=(32, 32, 32),
                 split_id=0,
                 samples=1000,
                 load=False):
        self.mode = mode
        self.root = dataset_path
        self.classes = classes
        dataset_name = 'MICCAI_2020_ribfrac'
        self.val_path = "/data/chelx/MICCAI-RibFrac2020/dataset/ribfrac-val-images"
        self.dirs = os.listdir(self.val_path)
        self.sample = samples
        self.list = []
        self.full_vol_size = (240, 240, 48)
        self.threshold = args.threshold
        self.crop_dim = dim
        self.list_reg_t1 = []
        self.labels = []
        self.full_volume = None
        self.save_name = self.root + '/MICCAI_2020_ribfrac/val/classes-' + str(
            classes) + '-list-' + mode + '-samples-' + str(samples) + '.txt'
        if load:
            ## load pre-generated data
            self.list = utils.load_list(self.save_name)
            return
        # subvol = '_vol_' + str(dim[0]) + 'x' + str(dim[1]) + 'x' + str(dim[2]) + '_' + str(self.threshold)
        # subvol = '_vol_' + str(dim[0]) + 'x' + str(dim[1]) + 'x' + str(dim[2]) + '_' + str(self.threshold) + '_' + str(args.samples_train)
        subvol = '_vol_' + str(dim[0]) + 'x' + str(dim[1]) + 'x' + str(
            dim[2]) + '_' + str(self.threshold) + '_overall'

        self.sub_vol_path = self.root + '/MICCAI_2020_ribfrac/generated/' + mode + subvol + '/'
        # utils.make_dirs(self.sub_vol_path)
        if not os.path.exists(self.sub_vol_path):
            os.makedirs(self.sub_vol_path)
        if not os.path.exists(os.path.dirname(self.save_name)):
            os.makedirs(os.path.dirname(self.save_name))

        list_reg_t1 = sorted(
            glob.glob(os.path.join(self.val_path, 'val/*.nii.gz')))
        # import ipdb;ipdb.set_trace()
        labels = sorted(
            glob.glob(os.path.join(self.val_path, 'val_label_gt/*.nii.gz')))

        self.affine = img_loader.load_affine_matrix(list_reg_t1[0])

        self.list = create_sub_volumes(list_reg_t1,
                                       labels,
                                       dataset_name=dataset_name,
                                       mode=mode,
                                       samples=samples,
                                       full_vol_dim=self.full_vol_size,
                                       crop_size=self.crop_dim,
                                       sub_vol_path=self.sub_vol_path,
                                       th_percent=self.threshold)

        utils.save_list(self.save_name, self.list)
Exemple #2
0
    def __init__(self, args, mode, dataset_path='../datasets', classes=4, dim=(32, 32, 32), split_id=0, samples=1000,
                 load=False):
        self.mode = mode
        self.root = dataset_path
        self.classes = classes
        dataset_name = "mrbrains" + str(classes)
        self.training_path = self.root + '/mrbrains_2018/training'
        self.dirs = os.listdir(self.training_path)
        self.samples = samples
        self.list = []
        self.full_vol_size = (240, 240, 48)
        self.threshold = 0.1
        self.crop_dim = dim
        self.list_flair = []
        self.list_ir = []
        self.list_reg_ir = []
        self.list_reg_t1 = []
        self.labels = []
        self.full_volume = None
        self.save_name = self.root + '/mrbrains_2018/training/mrbrains_2018-classes-' + str(
            classes) + '-list-' + mode + '-samples-' + str(
            samples) + '.txt'

        if load:
            ## load pre-generated data
            self.list = utils.load_list(self.save_name)
            return

        subvol = '_vol_' + str(dim[0]) + 'x' + str(dim[1]) + 'x' + str(dim[2])
        self.sub_vol_path = self.root + '/mrbrains_2018/generated/' + mode + subvol + '/'
        utils.make_dirs(self.sub_vol_path)

        list_reg_t1 = sorted(glob.glob(os.path.join(self.training_path, '*/pr*/*g_T1.nii.gz')))
        list_reg_ir = sorted(glob.glob(os.path.join(self.training_path, '*/pr*/*g_IR.nii.gz')))
        list_flair = sorted(glob.glob(os.path.join(self.training_path, '*/pr*/*AIR.nii.gz')))
        labels = sorted(glob.glob(os.path.join(self.training_path, '*/*egm.nii.gz')))
        self.affine = img_loader.load_affine_matrix(list_reg_t1[0])

        split_id = int(split_id)
        if mode == 'val':
            labels = [labels[split_id]]
            list_reg_t1 = [list_reg_t1[split_id]]
            list_reg_ir = [list_reg_ir[split_id]]
            list_flair = [list_flair[split_id]]
            self.full_volume = get_viz_set(list_reg_t1, list_reg_ir, list_flair, labels, dataset_name=dataset_name)
        else:
            labels.pop(split_id)
            list_reg_t1.pop(split_id)
            list_reg_ir.pop(split_id)
            list_flair.pop(split_id)

        self.list = create_sub_volumes(list_reg_t1, list_reg_ir, list_flair, labels,
                                       dataset_name=dataset_name, mode=mode,
                                       samples=samples, full_vol_dim=self.full_vol_size,
                                       crop_size=self.crop_dim, sub_vol_path=self.sub_vol_path,
                                       th_percent=self.threshold)

        utils.save_list(self.save_name, self.list)
    def __init__(self, args, mode, split_id, dataset_path='./datasets'):
        self.mode = mode
        self.root = dataset_path
        self.save_txt_name = os.path.join(dataset_path, 'cbct', mode) + '.txt'
        #todo
        self.affine = np.zeros((4, 4))
        self.full_volume = [64, 64, 64, 1]
        self.load = args.loadData
        img_npy_list = sorted(
            os.listdir(os.path.join(dataset_path, 'cbct', 'image')))

        if self.load:
            self.list = utils.load_list(self.save_txt_name)
            return

        if self.mode == 'train':
            npy_list = img_npy_list[:split_id]
            self.list = subvolume(dataset_path, npy_list, self.mode)
        elif self.mode == 'val':
            npy_list = img_npy_list[split_id:]
            self.list = subvolume(dataset_path, npy_list, self.mode)
            #todo

        save_list(self.save_txt_name, self.list)
Exemple #4
0
    def __init__(self,
                 mode,
                 dataset_path='./datasets',
                 crop_dim=(32, 32, 32),
                 split_id=1,
                 samples=1000,
                 load=False):
        """
        :param mode: 'train','val','test'
        :param dataset_path: root dataset folder
        :param crop_dim: subvolume tuple
        :param fold_id: 1 to 10 values
        :param samples: number of sub-volumes that you want to create
        """
        self.mode = mode
        self.root = str(dataset_path)
        self.training_path = self.root + '/iseg_2017/iSeg-2017-Training/'
        self.testing_path = self.root + '/iseg_2017/iSeg-2017-Testing/'
        self.CLASSES = 4
        self.full_vol_dim = (144, 192, 256)  # slice, width, height
        self.crop_size = crop_dim
        self.list = []
        self.samples = samples
        self.full_volume = None
        self.save_name = self.root + '/iseg_2017/iSeg-2017-Training/iseg2017-list-' + mode + '-samples-' + str(
            samples) + '.txt'

        if load:
            self.list = utils.load_list(self.save_name)
            list_IDsT1 = sorted(
                glob.glob(os.path.join(self.training_path, '*T1.img')))
            self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
            return

        subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(
            crop_dim[1]) + 'x' + str(crop_dim[2])
        self.sub_vol_path = self.root + '/iseg_2017/generated/' + mode + subvol + '/'
        utils.make_dirs(self.sub_vol_path)

        list_IDsT1 = sorted(
            glob.glob(os.path.join(self.training_path, '*T1.img')))
        list_IDsT2 = sorted(
            glob.glob(os.path.join(self.training_path, '*T2.img')))
        labels = sorted(
            glob.glob(os.path.join(self.training_path, '*label.img')))
        self.affine = img_loader.load_affine_matrix(list_IDsT1[0])

        if self.mode == 'train':
            list_IDsT1 = list_IDsT1[:split_id]
            list_IDsT2 = list_IDsT2[:split_id]
            labels = labels[:split_id]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT2,
                                           labels,
                                           dataset_name="iseg2017",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           threshold=10)

        elif self.mode == 'val':
            list_IDsT1 = list_IDsT1[split_id:]
            list_IDsT2 = list_IDsT2[:split_id:]
            labels = labels[split_id:]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT2,
                                           labels,
                                           dataset_name="iseg2017",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           threshold=10)

            self.full_volume = get_viz_set(list_IDsT1, list_IDsT2, labels)

        elif self.mode == 'test':
            self.list_IDsT1 = sorted(
                glob.glob(os.path.join(self.testing_path, '*T1.img')))
            self.list_IDsT2 = sorted(
                glob.glob(os.path.join(self.testing_path, '*T2.img')))
            self.labels = None

        utils.save_list(self.save_name, self.list)
Exemple #5
0
    def __init__(self,
                 args,
                 mode,
                 dataset_path='./datasets',
                 classes=5,
                 crop_dim=(32, 32, 32),
                 split_idx=10,
                 samples=10,
                 load=False):
        """
        :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.mode = mode
        self.root = str(dataset_path)
        self.training_path = self.root + '/MICCAI_BraTS_2018_Data_Training/'
        self.testing_path = self.root + ' '
        self.CLASSES = 4
        self.full_vol_dim = (240, 240, 155)  # slice, width, height
        self.crop_size = crop_dim
        self.threshold = args.threshold
        self.normalization = args.normalization
        self.augmentation = args.augmentation
        self.list = []
        self.samples = samples
        self.full_volume = None
        self.classes = classes
        self.save_name = self.root + '/MICCAI_BraTS_2018_Data_Training/brats2018-list-' + mode + '-samples-' + str(
            samples) + '.txt'
        if self.augmentation:
            self.transform = augment3D.RandomChoice(transforms=[
                augment3D.GaussianNoise(mean=0, std=0.01),
                augment3D.RandomFlip(),
                augment3D.ElasticTransform()
            ],
                                                    p=0.5)
        if load:
            ## load pre-generated data
            list_IDsT1 = sorted(
                glob.glob(os.path.join(self.training_path,
                                       '*GG/*/*t1.nii.gz')))
            self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
            self.list = utils.load_list(self.save_name)
            return

        subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(
            crop_dim[1]) + 'x' + str(crop_dim[2])
        self.sub_vol_path = self.root + '/MICCAI_BraTS_2018_Data_Training/generated/' + mode + subvol + '/'
        utils.make_dirs(self.sub_vol_path)

        list_IDsT1 = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t1.nii.gz')))
        list_IDsT1ce = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t1ce.nii.gz')))
        list_IDsT2 = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t2.nii.gz')))
        list_IDsFlair = sorted(
            glob.glob(os.path.join(self.training_path,
                                   '*GG/*/*_flair.nii.gz')))
        labels = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*_seg.nii.gz')))
        # print(len(list_IDsT1),len(list_IDsT2),len(list_IDsFlair),len(labels))

        self.affine = img_loader.load_affine_matrix(list_IDsT1[0])

        if self.mode == 'train':
            list_IDsT1 = list_IDsT1[:split_idx]
            list_IDsT1ce = list_IDsT1ce[:split_idx]
            list_IDsT2 = list_IDsT2[:split_idx]
            list_IDsFlair = list_IDsFlair[:split_idx]
            labels = labels[:split_idx]

            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT1ce,
                                           list_IDsT2,
                                           list_IDsFlair,
                                           labels,
                                           dataset_name="brats2018",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           normalization=self.normalization,
                                           th_percent=self.threshold)
        elif self.mode == 'val':
            list_IDsT1 = list_IDsT1[split_idx:]
            list_IDsT1ce = list_IDsT1ce[split_idx:]
            list_IDsT2 = list_IDsT2[split_idx:]
            list_IDsFlair = list_IDsFlair[split_idx:]
            labels = labels[split_idx:]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT1ce,
                                           list_IDsT2,
                                           list_IDsFlair,
                                           labels,
                                           dataset_name="brats2018",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           normalization=self.normalization,
                                           th_percent=self.threshold)

        elif self.mode == 'test':
            self.list_IDsT1 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t1.nii.gz')))
            self.list_IDsT1ce = sorted(
                glob.glob(os.path.join(self.testing_path,
                                       '*GG/*/*t1ce.nii.gz')))
            self.list_IDsT2 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t2.nii.gz')))
            self.list_IDsFlair = sorted(
                glob.glob(
                    os.path.join(self.testing_path, '*GG/*/*_flair.nii.gz')))
            self.labels = None

        utils.save_list(self.save_name, self.list)
Exemple #6
0
    def __init__(self,
                 args,
                 mode,
                 dataset_path='./datasets',
                 crop_dim=(32, 32, 32),
                 split_id=1,
                 samples=1000,
                 load=False):
        """
        :param mode: 'train','val','test'
        :param dataset_path: root dataset folder
        :param crop_dim: subvolume tuple
        :param fold_id: 1 to 10 values
        :param samples: number of sub-volumes that you want to create
        """
        self.mode = mode
        self.root = str(dataset_path)
        self.training_path = self.root + '/iseg_2019/iSeg-2019-Training/'
        self.testing_path = self.root + '/iseg_2019/iSeg-2019-Validation/'
        self.CLASSES = 4
        self.full_vol_dim = (144, 192, 256)  # slice, width, height
        self.crop_size = crop_dim
        self.threshold = args.threshold
        self.normalization = args.normalization
        self.augmentation = args.augmentation
        self.list = []
        self.samples = samples
        self.full_volume = None
        self.save_name = self.root + '/iseg_2019/iseg2019-list-' + mode + '-samples-' + str(
            samples) + '.txt'
        if self.augmentation:
            self.transform = augment3D.RandomChoice(transforms=[
                augment3D.GaussianNoise(mean=0, std=0.01),
                augment3D.RandomFlip(),
                augment3D.ElasticTransform()
            ],
                                                    p=0.5)
        if load:
            ## load pre-generated data
            self.list = utils.load_list(self.save_name)
            list_IDsT1 = sorted(
                glob.glob(os.path.join(self.training_path, '*T1.img')))
            self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
            return

        subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(
            crop_dim[1]) + 'x' + str(crop_dim[2])
        self.sub_vol_path = self.root + '/iseg_2019/generated/' + mode + subvol + '/'
        utils.make_dirs(self.sub_vol_path)

        list_IDsT1 = sorted(
            glob.glob(os.path.join(self.training_path, '*T1.img')))
        list_IDsT2 = sorted(
            glob.glob(os.path.join(self.training_path, '*T2.img')))
        labels = sorted(
            glob.glob(os.path.join(self.training_path, '*label.img')))
        self.affine = img_loader.load_affine_matrix(list_IDsT1[0])

        if self.mode == 'train':
            list_IDsT1 = list_IDsT1[:split_id]
            list_IDsT2 = list_IDsT2[:split_id]
            labels = labels[:split_id]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT2,
                                           labels,
                                           dataset_name="iseg2019",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           th_percent=self.threshold)

        elif self.mode == 'val':
            list_IDsT1 = list_IDsT1[split_id:]
            list_IDsT2 = list_IDsT2[:split_id:]
            labels = labels[split_id:]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT2,
                                           labels,
                                           dataset_name="iseg2019",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           th_percent=self.threshold)

            self.full_volume = get_viz_set(list_IDsT1,
                                           list_IDsT2,
                                           labels,
                                           dataset_name="iseg2019")

        elif self.mode == 'test':
            self.list_IDsT1 = sorted(
                glob.glob(os.path.join(self.testing_path, '*T1.img')))
            self.list_IDsT2 = sorted(
                glob.glob(os.path.join(self.testing_path, '*T2.img')))
            self.labels = None
            # todo inference here

        utils.save_list(self.save_name, self.list)
Exemple #7
0
    def __init__(self,
                 args,
                 mode,
                 dataset_path='../../datasets',
                 classes=4,
                 crop_dim=(128, 128, 128),
                 split_idx=204,
                 samples=10,
                 load=False):
        """
        :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.mode = mode
        self.root = str(dataset_path)
        self.training_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/train_generated'
        self.testing_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Validation/'
        self.full_vol_dim = (128, 128, 128)  # slice, width, height
        self.crop_size = crop_dim
        self.threshold = args.threshold
        self.normalization = args.normalization
        self.augmentation = args.augmentation
        self.list = []
        self.samples = samples
        self.full_volume = None
        self.classes = classes
        if self.augmentation:
            self.transform = augment3D.RandomChoice(transforms=[
                augment3D.GaussianNoise(mean=0, std=0.01),
                augment3D.RandomFlip(),
                augment3D.ElasticTransform()
            ],
                                                    p=0.5)
        self.save_name = self.root + '/brats2019/brats2019-list-' + mode + '-samples-' + str(
            samples) + '.txt'

        if load:
            ## load pre-generated data
            self.list = utils.load_list(self.save_name)
            list_IDsT1 = sorted(
                glob.glob(
                    os.path.join(self.training_path,
                                 '***_imgs/***_imgs_t1.npy')))
            # self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
            return

        subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(
            crop_dim[1]) + 'x' + str(crop_dim[2])
        self.sub_vol_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/generated/' + mode + subvol + '/'

        # if not os.path.exists(self.sub_vol_path):
        #     utils.make_dirs(self.sub_vol_path)

        list_IDsT1 = sorted(
            glob.glob(
                os.path.join(self.training_path, '***_imgs/***_imgs_t1.npy')))
        list_IDsT1ce = sorted(
            glob.glob(
                os.path.join(self.training_path,
                             '***_imgs/***_imgs_t1gd.npy')))
        list_IDsT2 = sorted(
            glob.glob(
                os.path.join(self.training_path, '***_imgs/***_imgs_t2.npy')))
        list_IDsFlair = sorted(
            glob.glob(
                os.path.join(self.training_path,
                             '***_imgs/***_imgs_flair.npy')))
        labels = sorted(
            glob.glob(
                os.path.join(self.training_path, '***_seg/***_seg_label.npy')))
        # list_IDsT1, list_IDsT1ce, list_IDsT2, list_IDsFlair, labels = utils.shuffle_lists(list_IDsT1, list_IDsT1ce,
        #                                                                                   list_IDsT2,
        #                                                                                   list_IDsFlair, labels,
        #                                                                                   seed=17)
        self.affine = np.diag([1, 1, 1, 1])

        if self.mode == 'train':

            list_IDsT1 = list_IDsT1[:split_idx]
            list_IDsT1ce = list_IDsT1ce[:split_idx]
            list_IDsT2 = list_IDsT2[:split_idx]
            list_IDsFlair = list_IDsFlair[:split_idx]
            labels = labels[:split_idx]

            # self.list = create_sub_volumes(list_IDsT1, list_IDsT1ce, list_IDsT2, list_IDsFlair, labels,
            #                                dataset_name="brats2019", mode=mode, samples=samples,
            #                                full_vol_dim=self.full_vol_dim, crop_size=self.crop_size,
            #                                sub_vol_path=self.sub_vol_path, th_percent=self.threshold)
            # with open(self.save_name, "wb") as fp:
            #     pickle.dump(self.list,fp)
            with open(self.save_name, "rb") as fp:
                self.list = pickle.load(fp)
        elif self.mode == 'val':
            list_IDsT1 = list_IDsT1[split_idx:]
            list_IDsT1ce = list_IDsT1ce[split_idx:]
            list_IDsT2 = list_IDsT2[split_idx:]
            list_IDsFlair = list_IDsFlair[split_idx:]
            labels = labels[split_idx:]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT1ce,
                                           list_IDsT2,
                                           list_IDsFlair,
                                           labels,
                                           dataset_name="brats2019",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path,
                                           th_percent=self.threshold)
            with open(self.save_name, "wb") as fp:
                pickle.dump(self.list, fp)
            # with open(self.save_name, "rb") as fp:
            #     self.list = pickle.load(fp)
        elif self.mode == 'test':
            self.list_IDsT1 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t1.nii.gz')))
            self.list_IDsT1ce = sorted(
                glob.glob(os.path.join(self.testing_path,
                                       '*GG/*/*t1ce.nii.gz')))
            self.list_IDsT2 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t2.nii.gz')))
            self.list_IDsFlair = sorted(
                glob.glob(
                    os.path.join(self.testing_path, '*GG/*/*_flair.nii.gz')))
            self.labels = None
Exemple #8
0
    def __init__(self,
                 mode,
                 dataset_path='./datasets',
                 classes=5,
                 crop_dim=(200, 200, 150),
                 split_idx=260,
                 samples=10,
                 load=False):
        """
        :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.mode = mode
        self.root = str(dataset_path)
        self.training_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/'
        self.testing_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Validation/'
        self.full_vol_dim = (240, 240, 155)  # slice, width, height
        self.crop_size = crop_dim
        self.list = []
        self.samples = samples
        self.full_volume = None
        self.classes = classes

        self.save_name = self.root + '/brats2019/brats2019-list-' + mode + '-samples-' + str(
            samples) + '.txt'

        if load:
            self.list = utils.load_list(self.save_name)
            list_IDsT1 = sorted(
                glob.glob(os.path.join(self.training_path,
                                       '*GG/*/*t1.nii.gz')))
            self.affine = img_loader.load_affine_matrix(list_IDsT1[0])
            return

        subvol = '_vol_' + str(crop_dim[0]) + 'x' + str(
            crop_dim[1]) + 'x' + str(crop_dim[2])
        self.sub_vol_path = self.root + '/brats2019/MICCAI_BraTS_2019_Data_Training/generated/' + mode + subvol + '/'
        utils.make_dirs(self.sub_vol_path)

        list_IDsT1 = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t1.nii.gz')))
        list_IDsT1ce = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t1ce.nii.gz')))
        list_IDsT2 = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*t2.nii.gz')))
        list_IDsFlair = sorted(
            glob.glob(os.path.join(self.training_path,
                                   '*GG/*/*_flair.nii.gz')))
        labels = sorted(
            glob.glob(os.path.join(self.training_path, '*GG/*/*_seg.nii.gz')))
        list_IDsT1, list_IDsT1ce, list_IDsT2, list_IDsFlair, labels = utils.shuffle_lists(
            list_IDsT1,
            list_IDsT1ce,
            list_IDsT2,
            list_IDsFlair,
            labels,
            seed=17)
        self.affine = img_loader.load_affine_matrix(list_IDsT1[0])

        if self.mode == 'train':
            print('Brats2019, Total data:', len(list_IDsT1))
            list_IDsT1 = list_IDsT1[:split_idx]
            list_IDsT1ce = list_IDsT1ce[:split_idx]
            list_IDsT2 = list_IDsT2[:split_idx]
            list_IDsFlair = list_IDsFlair[:split_idx]
            labels = labels[:split_idx]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT1ce,
                                           list_IDsT2,
                                           list_IDsFlair,
                                           labels,
                                           dataset_name="brats2019",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path)

        elif self.mode == 'val':
            list_IDsT1 = list_IDsT1[split_idx:]
            list_IDsT1ce = list_IDsT1ce[split_idx:]
            list_IDsT2 = list_IDsT2[split_idx:]
            list_IDsFlair = list_IDsFlair[split_idx:]
            labels = labels[split_idx:]
            self.list = create_sub_volumes(list_IDsT1,
                                           list_IDsT1ce,
                                           list_IDsT2,
                                           list_IDsFlair,
                                           labels,
                                           dataset_name="brats2019",
                                           mode=mode,
                                           samples=samples,
                                           full_vol_dim=self.full_vol_dim,
                                           crop_size=self.crop_size,
                                           sub_vol_path=self.sub_vol_path)
        elif self.mode == 'test':
            self.list_IDsT1 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t1.nii.gz')))
            self.list_IDsT1ce = sorted(
                glob.glob(os.path.join(self.testing_path,
                                       '*GG/*/*t1ce.nii.gz')))
            self.list_IDsT2 = sorted(
                glob.glob(os.path.join(self.testing_path, '*GG/*/*t2.nii.gz')))
            self.list_IDsFlair = sorted(
                glob.glob(
                    os.path.join(self.testing_path, '*GG/*/*_flair.nii.gz')))
            self.labels = None
            # Todo inference code here

        utils.save_list(self.save_name, self.list)