def Create_data(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param, shuffle): # Create training and validation data if shuffle: nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param, shuffle_TD_VD=True) else: nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param)
def NNFDK_obj(CT_obj, phantom, pix, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param, bpath): nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, base_path=bpath) spf_space, Exp_op = ddf.support_functions.ExpOp_builder( bin_param, CT_obj.filter_space, interp=Exp_bin) # Create the FDK binned operator CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op # Create the NN-FDK object CT_obj.NNFDK = nn.NNFDK_class(CT_obj, nTrain, nTD, nVal, nVD, Exp_bin, Exp_op, bin_param, base_path=bpath) CT_obj.rec_methods += [CT_obj.NNFDK] return CT_obj
def create_datasets(pix, phantom, angles, src_rad, noise, nTD, nVD, Exp_bin, bin_param, bpath): nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, base_path=bpath)
def main(pix, phantom, nTD, nTrain, nVD, nVal, train, bpath, stop_crit, MSD, PH, angles, src_rad, det_rad, noise, Exp_bin, bin_param, epochs, save_model_pb): # Specific phantom # %% t1 = time.time() nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, base_path=bpath) print('Creating training and validation datasets took', time.time() - t1, 'seconds') voxels = [pix, pix, pix] # %% Create a test phantom data_path = nn.make_data_path(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, base_path=bpath) l_tr, l_v = nn.Preprocess_datasets.random_lists(nTD, nVD) list_tr = [i for i in range(10)] list_v = [i + 10 for i in range(5)] if MSD: import MSD_functions as msd MSD = msd.MSD_class(None, data_path) MSD.train(list_tr, list_v, stop_crit=stop_crit, ratio=3, save_model_pb=save_model_pb) else: import Unet_functions as unet Unet = unet.Unet_class(None, data_path) Unet.train(list_tr, list_v, epochs=epochs, stop_crit=stop_crit, ratio=3, save_model_pb=save_model_pb) return
def main(pix, phantom, nTD, nTrain, nVD, nVal, train, bpath, stop_crit, PH, angles, src_rad, det_rad, noise, Exp_bin, bin_param): # Specific phantom # %% t1 = time.time() nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, base_path=bpath) print('Creating training and validation datasets took', time.time() - t1, 'seconds') # %% Create a test phantom voxels = [pix, pix, pix] # Create a data object t2 = time.time() if not train: data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, det_rad)#, # compute_xHQ=True) print('Making phantom and mask took', time.time() -t2, 'seconds') # The amount of projection angles in the measurements # Source to center of rotation radius t3 = time.time() # %% Create the circular cone beam CT class case = ddf.CCB_CT(data_obj)#, angles, src_rad, det_rad, noise) print('Making data and operators took', time.time()-t3, 'seconds') # Initialize the algorithms (FDK, SIRT) t4 = time.time() case.init_algo() # %% Create NN-FDK algorithm setup # Create binned filter space and expansion operator spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param, case.filter_space, interp=Exp_bin) # Create the FDK binned operator case.FDK_bin_nn = case.FDK_op * Exp_op # Create the NN-FDK object case.NNFDK = nn.NNFDK_class(case, nTrain, nTD, nVal, nVD, Exp_bin, Exp_op, bin_param, base_path=bpath) case.rec_methods += [case.NNFDK] case.MSD = msd.MSD_class(case, case.NNFDK.data_path) case.rec_methods += [case.MSD] print('Initializing algorithms took', time.time() - t4, 'seconds') else: data_path = nn.make_data_path(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, base_path=bpath) MSD = msd.MSD_class(None, data_path) # %% l_tr, l_v = nn.Preprocess_datasets.random_lists(nTD, nVD) if nVD == 0: list_tr = [0] list_v = None elif nVD == 1: list_tr = [0] list_v = [1] else: list_tr = [i for i in range(10)] list_v = [i + 10 for i in range(5)] if train: print('Started training function') MSD.train(list_tr, list_v, stop_crit=stop_crit, ratio=3) else: case.MSD.add2sp_list(list_tr, list_v) case.MSD.do() # %% print('MSD rec time:', case.MSD.results.rec_time[0]) # print('NNFDK rec time:', case.NNFDK.results.rec_time[0]) # print('FDK rec time:', case.FDK.results.rec_time[0]) # %% save_path = '/bigstore/lagerwer/NNFDK_results/figures/' pylab.close('all') case.table() case.show_phantom() case.MSD.show(save_name=f'{save_path}MSD_{PH}_nTD{nTD}_nVD{nVD}')
import numpy as np import nn_fdk as nn import gc # %% pix = 1024 # Specific phantom phantom = 'Fourshape' # Number of angles ang = [8, 16, 32, 64, 128] # Source radius src_rad = 10 # Noise specifics noise = None nTrain, nTD, nVal, nVD = 1e6, 100, 1e6, 100 # Specifics for the expansion operator Exp_bin = 'linear' bin_param = 2 # %% for angles in ang: data_path, _ = nn.make_map_path(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param) nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, nTrain, nTD, nVal, nVD, Exp_bin, bin_param)
noise = None #['Poisson', 2 ** 10] # Number of voxels used for training, number of datasets used for training nTrain, nTD = 1e5, 8 # Number of voxels used for validation, number of datasets used for validation nVal, nVD = 1e5, 8 MVD = int(25e5) # Specifics for the expansion operator Exp_bin = 'linear' bin_param = 2 nTests = 10 #'/export/scratch1/home/voxels-gpu0/data/NNFDK/' # %% t1 = time.time() nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, MaxVoxDataset=MVD) print('Creating training and validation datasets took', time.time() - t1, 'seconds') # %% Create a test phantom voxels = [pix, pix, pix] # Create a data object t2 = time.time() data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, det_rad) print('Making phantom and mask took', time.time() -t2, 'seconds') # The amount of projection angles in the measurements # Source to center of rotation radius t3 = time.time()
def main(phantom, nTD, nVD, train): pix = 1024 # Specific phantom if phantom == 'Fourshape_test': PH = '4S' src_rad = 10 noise = ['Poisson', 2**8] elif phantom == 'Defrise': PH = 'DF' src_rad = 2 noise = None # Number of angles angles = 360 # Source radius det_rad = 0 # Noise specifics # Number of voxels used for training, number of datasets used for training nTrain = 1e6 # Number of voxels used for validation, number of datasets used for validation nVal = 1e6 # Specifics for the expansion operator Exp_bin = 'linear' bin_param = 2 bpath = '/export/scratch2/lagerwer/data/NNFDK/' # %% t1 = time.time() nn.Create_TrainingValidationData(pix, phantom, angles, src_rad, noise, Exp_bin, bin_param, nTD + nVD, base_path=bpath) print('Creating training and validation datasets took', time.time() - t1, 'seconds') # %% Create a test phantom voxels = [pix, pix, pix] # Create a data object t2 = time.time() data_obj = ddf.phantom(voxels, phantom, angles, noise, src_rad, det_rad) #, # compute_xHQ=True) print('Making phantom and mask took', time.time() - t2, 'seconds') # The amount of projection angles in the measurements # Source to center of rotation radius t3 = time.time() # %% Create the circular cone beam CT class case = ddf.CCB_CT(data_obj) #, angles, src_rad, det_rad, noise) print('Making data and operators took', time.time() - t3, 'seconds') # Initialize the algorithms (FDK, SIRT) t4 = time.time() case.init_algo() # %% Create NN-FDK algorithm setup # Create binned filter space and expansion operator spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param, case.filter_space, interp=Exp_bin) # Create the FDK binned operator case.FDK_bin_nn = case.FDK_op * Exp_op # Create the NN-FDK object case.NNFDK = nn.NNFDK_class(case, nTrain, nTD, nVal, nVD, Exp_bin, Exp_op, bin_param, base_path=bpath) case.rec_methods += [case.NNFDK] print('Initializing algorithms took', time.time() - t4, 'seconds') # %% if not train: case.FDK.do('Hann') case.NNFDK.train(4) case.NNFDK.do()