def build_cnn_for_recon(batch_size=10): # output cnn recon images(with alias) from the undersample k-space im parser = argparse.ArgumentParser() parser.add_argument('--lr', metavar='float', nargs=1, default=['0.001'], help='initial learning rate') parser.add_argument('--l2', metavar='float', nargs=1, default=['1e-6'], help='l2 regularisation') args = parser.parse_args() Nx, Ny = 128, 128 # Specify network input_shape = (batch_size, 2, Nx, Ny) # Comnstruct and Load D5-C5 with pretrained params net_config, net, = build_d5_c5(input_shape) with np.load('./models/pretrained/d5_c5.npz') as f: param_values = [f['arr_{0}'.format(i)] for i in range(len(f.files))] lasagne.layers.set_all_param_values(net, param_values) # Compile function train_fn, val_fn = compile_fn(net, net_config, args) return val_fn
def load_network(input_shape, network_path=network_path): """ Loads the pretrained network, specified by the absolute_path. :param input_shape: - (batch_size, 2, Nx, Ny) :param network_path: - path to network weights :returns: net_config, network """ #input_shape = (batch_size, 2, Nx, Ny) #net_config, net, = build_d2_c2(input_shape) # Load D5-C5 with pretrained params net_config, network, = build_d5_c5(input_shape) # D5-C5 with pre-trained parameters with np.load(network_path) as f: param_values = [f['arr_{0}'.format(i)] for i in range(len(f.files))] lasagne.layers.set_all_param_values(network, param_values) return net_config, network
save_every = 5 # Configure directory info project_root = '.' save_dir = join(project_root, 'models/%s' % model_name) if not os.path.isdir(save_dir): os.makedirs(save_dir) # Create dataset n_train, n_validate, n_test = 160, 40, 56 train, validate, test = create_dummy_data([n_train, n_validate, n_test]) # Specify network input_shape = (batch_size, 2, Nx, Ny) # net_config, net, = build_d2_c2(input_shape) net_config, net, = build_d5_c5(input_shape) # D5-C5 with pre-trained parameters # with np.load('./models/pretrained/d5_c5.npz') as f: # param_values = [f['arr_{0}'.format(i)] for i in range(len(f.files))] # lasagne.layers.set_all_param_values(net, param_values) print('Undersampling Rate: {:.2f}'.format(1 / acc)) # Compile function train_fn, val_fn = compile_fn(net, net_config, args) print('Start Training...') for epoch in xrange(num_epoch): t_start = time.time()