def preprocess_setup(preprocessed_data_dir):
    print('Preparing for preprocessing data...')
    fold = 1
    validation_fold_file = '../models/image_segmentation/tensorflow/3d_unet_mlperf/inference/nnUNet/folds/fold1_validation.txt'
    model_dir = 'build/result/nnUNet/3d_fullres/Task043_BraTS2019/nnUNetTrainerV2__nnUNetPlansv2.mlperf.1'
    model_path = os.path.join(model_dir, 'plans.pkl')
    assert os.path.isfile(model_path), 'Cannot find the model file {:}!'.format(model_path)
    checkpoint_name = 'model_final_checkpoint'
    fp16 = False
    num_threads_preprocessing = 12
    raw_data_dir = 'build/raw_data/nnUNet_raw_data/Task043_BraTS2019/imagesTr'
    validation_files = []
    with open(validation_fold_file) as f:
        for line in f:
            validation_files.append(line.rstrip())
    if (not os.path.isdir(preprocessed_data_dir)):
        os.makedirs(preprocessed_data_dir)
    all_files = subfiles(raw_data_dir, suffix='.nii.gz', join=False, sort=True)
    list_of_lists = [[os.path.join(raw_data_dir, i) for i in all_files if (i[:len(j)].startswith(j) and (len(i) == (len(j) + 12)))] for j in validation_files]
    print('Acually preprocessing data...')
    preprocessed_files = preprocess_MLPerf(model_dir, checkpoint_name, fold, fp16, list_of_lists, validation_files, preprocessed_data_dir, num_threads_preprocessing)
    print('Saving metadata of the preprocessed data...')
    with open(os.path.join(preprocessed_data_dir, 'preprocessed_files.pkl'), 'wb') as f:
        pickle.dump(preprocessed_files, f)
    print('Preprocessed data saved to {:}'.format(preprocessed_data_dir))
    print('Done!')
def preprocess_setup(preprocessed_data_dir):
    print('Preparing for preprocessing data...')
    fold = 1
    validation_fold_file = '../models/image_segmentation/tensorflow/3d_unet_mlperf/inference/nnUNet/folds/fold1_validation.txt'
    model_dir = 'build/result/nnUNet/3d_fullres/Task043_BraTS2019/nnUNetTrainerV2__nnUNetPlansv2.mlperf.1'
    model_path = os.path.join(model_dir, 'plans.pkl')
    assert os.path.isfile(model_path), 'Cannot find the model file {:}!'.format(model_path)
    checkpoint_name = 'model_final_checkpoint'
    fp16 = False
    num_threads_preprocessing = 12
    raw_data_dir = 'build/raw_data/nnUNet_raw_data/Task043_BraTS2019/imagesTr'
    validation_files = []
    with open(validation_fold_file) as f:
        for line in f:
            validation_files.append(line.rstrip())
    if (not os.path.isdir(preprocessed_data_dir)):
        os.makedirs(preprocessed_data_dir)
    all_files = subfiles(raw_data_dir, suffix='.nii.gz', join=False, sort=True)
    list_of_lists = [[os.path.join(raw_data_dir, i) for i in all_files if (i[:len(j)].startswith(j) and (len(i) == (len(j) + 12)))] for j in validation_files]
    print('Acually preprocessing data...')
    preprocessed_files = preprocess_MLPerf(model_dir, checkpoint_name, fold, fp16, list_of_lists, validation_files, preprocessed_data_dir, num_threads_preprocessing)
    print('Saving metadata of the preprocessed data...')
    with open(os.path.join(preprocessed_data_dir, 'preprocessed_files.pkl'), 'wb') as f:
        pickle.dump(preprocessed_files, f)
    print('Preprocessed data saved to {:}'.format(preprocessed_data_dir))
    print('Done!')