# # Import the data train_loader, test_loader = data_reader.read_data(flags) # Reset the boundary if normalized if flags.normalize_input: flags.geoboundary_norm = [-1, 1, -1, 1] print("Geometry boundary is set to:", flags.geoboundary) # Make Network print("Making network now") ntwk = Network(Lorentz, flags, train_loader, test_loader) # Training process print("Start training now...") #ntwk.pretrain() #ntwk.load_pretrain() ntwk.train() # Do the house keeping, write the parameters and put into folder, also use pickle to save the flags object write_flags_and_BVE(flags, ntwk.best_validation_loss, ntwk.ckpt_dir) # put_param_into_folder(ntwk.ckpt_dir) if __name__ == '__main__': # Read the parameters to be set flags = flagreader.read_flag() # Call the train from flag function training_from_flag(flags)
""" This .py file is to run train.py for hyper-parameter swipping in a linear fashion. """ import train #os.environ["CUDA_VISIBLE_DEVICE"] = "-1" #Uncomment this line if you want to use CPU only import numpy as np import flagreader if __name__ == '__main__': #linear_unit_list = [ 50, 100, 200, 500] #linear_unit_list = [1000, 500] #linear_unit_list = [1000] # reg_scale_list = [1e-5, 5e-5, 1e-4, 5e-4, 1e-3, 5e-3] #reg_scale_list = [5e-4] for num_lor in range(4, 8): flags = flagreader.read_flag() #setting the base case flags.num_lor = num_lor flags.spectra_save_dir = '/work/sr365/Christian_data_fit/num_lor' + str( num_lor) train.training_from_flag(flags) #for num_gaussian in range(3,15): # for linear_unit in linear_unit_list: #for kernel_first in conv_kernel_size_first_list: # for kernel_second in conv_kernel_size_second_list: # Setting the loop for setting the parameter #for i in range(5, 8): # flags = flag_reader.read_flag() #setting the base case # flags.data_set = 'sine_wave' # flags.ckpt_dir = '/work/sr365/MDN_results/' + flags.data_set # flags.num_gaussian = num_gaussian # Setting the number of gaussians # linear = [linear_unit for j in range(i)] #Set the linear units # linear[0] = 1 # The start of linear
test_loader, inference_mode=True, saved_model=flags.eval_model) # Evaluation process print("Start eval now:") pred_file, truth_file = ntwk.evaluate() # Plot the MSE distribution plotMSELossDistrib_eval(pred_file, truth_file, flags) print("Evaluation finished") def evaluate_all(models_dir="models"): """ This function evaluate all the models in the models/. directory :return: None """ for file in os.listdir(models_dir): if os.path.isfile(os.path.join(models_dir, file, 'flags.obj')): evaluate_from_model(os.path.join(models_dir, file)) return None if __name__ == '__main__': # Read the flag, however only the flags.eval_model is used and others are not used useless_flags = flagreader.read_flag() print(useless_flags.eval_model) # Call the evaluate function from model evaluate_from_model(useless_flags.eval_model)