def __init__(self, beta1=0.9, beta2=0.999, epsilon=1e-8, max_colm_norm=False, max_norm=15.0): self.beta1 = sharedX_value(beta1, name='beta1', borrow=True) self.beta2 = sharedX_value(beta2, name='beta2', borrow=True) self.epsilon = sharedX_value(epsilon, name='epsilon', borrow=True) self.max_colm_norm = max_colm_norm self.max_norm = max_norm
def __init__(self, decay=0.9, max_scaling=1e5, max_colm_norm=False, max_norm=15.0): assert 0. <= decay < 1., 'decay must be: 0. <= decay < 1' assert max_scaling > 0., 'max_scaling must be > 0.' self.decay = sharedX_value(decay, name='decay', borrow=True) self.epsilon = 1. / max_scaling self.mean_square_grads = None self._first_time = True self.max_colm_norm = max_colm_norm self.max_norm = max_norm
def __init__(self, init_momentum, nesterov_momentum=False, imagenet=False, imagenetDecay=5e-4, max_colm_norm=False, max_norm=15.0): assert init_momentum >= 0., 'The initial momentum should be >=0.' assert init_momentum < 1., 'The initial momentum should be < 1.' self.momentum = sharedX_value(value=init_momentum, name="momentum", borrow=True) self.nesterov_momentum = nesterov_momentum self._first_time = True self.velocity = None # tracks the velocity at the previous time self.imagenet = imagenet self.imagenetDecay = sharedX_value(value=imagenetDecay, name="imagenetDecay", borrow=True) self.max_colm_norm = max_colm_norm self.max_norm = max_norm
aes_in = [] aes_out = [] if id_code is not None: assert aes_out != [] # Train # Data tr_batch_size = 10 vl_batch_size = 8000 with open(path_valid, 'r') as f: l_samples_vl = pkl.load(f) list_minibatchs_vl = split_data_to_minibatchs_eval( l_samples_vl, vl_batch_size) max_epochs = int(1000) lr_vl = 1e-3 lr = sharedX_value(lr_vl, name="lr") # cost weights separate = True l_in = [sharedX_value(0., name="l_in"), sharedX_value(0.0, name="l_in2")] l_out = [sharedX_value(0., name="l_out")] l_sup = sharedX_value(1., name="l_sup") l_code = sharedX_value(0.0, name="l_code") if not separate: assert l_sup.get_value() + l_in.get_value() + l_out.get_value() == 1. if l_in[0].get_value() != 0. and aes_in == []: raise ValueError("You setup the l_in but no aes in found.") if l_out[0].get_value() != 0. and aes_out == []: raise ValueError("You setup the l_out but no aes out found.") # Train criterion cost_type = CostType.MeanSquared # CostType.MeanSquared # Compile the functions
"deep_conv_ae_init_" + id_deep_conv_ae + ".pkl" if not os.path.isfile(path_ini_params_deep_conv_ae): deep_conv_ae.save_params(path_ini_params_deep_conv_ae) else: deep_conv_ae.set_params_vals(path_ini_params_deep_conv_ae) with open(path_valid, 'r') as f: l_samples_vl = pkl.load(f) # convert to 3D nbr_xx = l_samples_vl["x"].shape[0] l_samples_vl["x"] = l_samples_vl["x"].reshape((nbr_xx, 1, h, w)) list_minibatchs_vl = split_data_to_minibatchs_eval(l_samples_vl, vl_batch_size) max_epochs = int(1000) lr_vl = 1e-4 lr = sharedX_value(lr_vl, name="lr") optimizer = "momentum" if optimizer == "adadelta": updater = AdaDelta(decay=0.95) elif optimizer == "momentum": updater = Momentum(0.9, nesterov_momentum=True, imagenet=False, imagenetDecay=5e-4, max_colm_norm=False) else: raise ValueError("Optimizer not recognized.") # Prepare costs. cost_train, _, _ = deep_conv_ae.get_train_cost() # updates