本文整理汇总了Python中lasagne.layers.get_all_param_values方法的典型用法代码示例。如果您正苦于以下问题:Python layers.get_all_param_values方法的具体用法?Python layers.get_all_param_values怎么用?Python layers.get_all_param_values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lasagne.layers
的用法示例。
在下文中一共展示了layers.get_all_param_values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadModel
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def loadModel(filename):
print "IMPORTING MODEL PARAMS...",
net_filename = MODEL_PATH + filename
with open(net_filename, 'rb') as f:
data = pickle.load(f)
#for training, we only want to load the model params
net = data['net']
params = l.get_all_param_values(net)
if LOAD_OUTPUT_LAYER:
l.set_all_param_values(NET, params)
else:
l.set_all_param_values(l.get_all_layers(NET)[:-1], params[:-2])
print "DONE!"
示例2: loadPretrained
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def loadPretrained(net):
if cfg.MODEL_NAME:
# Load saved model
n, c = io.loadModel(cfg.MODEL_NAME)
# Set params
params = l.get_all_param_values(n)
if cfg.LOAD_OUTPUT_LAYER:
l.set_all_param_values(net, params)
else:
l.set_all_param_values(l.get_all_layers(net)[:-1], params[:-2])
return net
#################### LOSS FUNCTION ######################
示例3: saveParams
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def saveParams(net, classes, epoch):
log.i("EXPORTING MODEL PARAMS...", new_line=False)
net_filename = cfg.MODEL_PATH + cfg.RUN_NAME + "_model_params_epoch_" + str(epoch) + ".pkl"
if not os.path.exists(cfg.MODEL_PATH):
os.makedirs(cfg.MODEL_PATH)
with open(net_filename, 'w') as f:
#We want to save the model params only and trained classes
params = l.get_all_param_values(net)
data = {'params': params, 'classes':classes, 'run_name': cfg.RUN_NAME, 'epoch':epoch, 'im_size':cfg.IM_SIZE, 'im_dim':cfg.IM_DIM}
pickle.dump(data, f)
log.i("DONE!")
return os.path.split(net_filename)[-1]
示例4: save_model
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def save_model(self, save_path):
with open(save_path, 'w') as f:
data = L.get_all_param_values(self.network)
pkl.dump(data, f)
for item in self.trackers:
data = L.get_all_param_values(item)
pkl.dump(data, f)
示例5: save_model
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def save_model(self, save_path):
data = L.get_all_param_values(self.network)
with open(save_path, 'w') as f:
pkl.dump(data, f)
示例6: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 4 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 15:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 50:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 100:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例7: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 10 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 10:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 40:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 80:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例8: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 10 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 10:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 20:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例9: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 10 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 40:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 100:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 200:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例10: exc_train
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def exc_train(train_func, X_train, network):
print("Starting training...");
print("Epoch\t\tIter\t\tLoss\t\tSpar\t\tTime");
it_div = 100;
for epoch in range(NumEpochs):
start_time = time.time();
for it in range(it_div):
# Iterate through mini batches
total_loss = 0;
total_sparsity = 0;
n_batch = 0;
for batch in iterate_minibatches_ae(X_train[it::it_div], BatchSize, shuffle=True):
batch = data_aug(batch);
batch_target = np.reshape(batch, (batch.shape[0], -1));
loss, mask = train_func(batch, batch_target);
total_loss += loss;
total_sparsity += 100.0 * float(np.count_nonzero(mask>1e-4)) / mask.size;
n_batch += 1;
total_loss /= n_batch;
total_sparsity /= n_batch;
LearningRate.set_value(np.float32(0.99*LearningRate.get_value()));
print("{:d}\t\t{:d}\t\t{:.4f}\t\t{:.3f}\t\t{:.3f}".format(
epoch, it, total_loss, total_sparsity, time.time()-start_time));
start_time = time.time();
if epoch % 1 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(filename_model_ae.format(epoch), 'w'));
示例11: exc_train
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def exc_train(train_func, X_train, network):
print("Starting training...");
print("Epoch\t\tIter\t\tLoss\t\tSpar\t\tTime");
it_div = 100;
for epoch in range(NumEpochs):
start_time = time.time();
for it in range(it_div):
# Iterate through mini batches
total_loss = 0;
total_sparsity = 0;
n_batch = 0;
for batch in iterate_minibatches_ae(X_train[it::it_div], BatchSize, shuffle=True):
batch = data_aug(batch);
batch_target = np.reshape(batch, (batch.shape[0], -1));
loss, mask = train_func(batch, batch_target);
total_loss += loss;
total_sparsity += 100.0 * float(np.count_nonzero(mask>1e-6)) / mask.size;
n_batch += 1;
total_loss /= n_batch;
total_sparsity /= n_batch;
LearningRate.set_value(np.float32(0.99*LearningRate.get_value()));
print("{:d}\t\t{:d}\t\t{:.4f}\t\t{:.3f}\t\t{:.3f}".format(
epoch, it, total_loss, total_sparsity, time.time()-start_time));
start_time = time.time();
if epoch % 1 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(filename_model_ae.format(epoch), 'w'));
示例12: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, y_train, X_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, y_train, BatchSize, shuffle = True):
inputs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 10 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 5:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 20:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 50:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例13: exc_train
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def exc_train(train_func, X_train, network):
print("Starting training...");
print("Epoch\t\tIter\t\tLoss\t\tSpar\t\tTime");
it_div = 100;
BatchSize = 2;
for epoch in range(NumEpochs):
start_time = time.time();
for it in range(it_div):
# Iterate through mini batches
total_loss = 0;
total_sparsity = 0;
n_batch = 0;
for batch in iterate_minibatches_ae(X_train[it::it_div], BatchSize, shuffle=True):
batch = data_aug(batch);
batch_target = np.reshape(batch, (batch.shape[0], -1));
loss, mask = train_func(batch, batch_target);
total_loss += loss;
total_sparsity += 100.0 * float(np.count_nonzero(mask>1e-6)) / mask.size;
if n_batch % 20 == 0:
sample_sparsity = 100.0 * float(np.count_nonzero(mask[0, ...]>1e-5)) / mask[0, ...].size;
print("============{:.3f}============".format(sample_sparsity));
n_batch += 1;
total_loss /= n_batch;
total_sparsity /= n_batch;
LearningRate.set_value(np.float32(0.99*LearningRate.get_value()));
print("{:d}\t\t{:d}\t\t{:.4f}\t\t{:.3f}\t\t{:.3f}".format(
epoch, it, total_loss, total_sparsity, time.time()-start_time));
start_time = time.time();
if (it % 10 == 0) and (it > 0):
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(filename_model_ae.format(epoch), 'w'));
if it % 2 == 0:
BatchSize += 1;
if BatchSize > BatchSizeMax: BatchSize = BatchSizeMax;
示例14: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 5 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 30:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 50:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 100:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
示例15: train_round
# 需要导入模块: from lasagne import layers [as 别名]
# 或者: from lasagne.layers import get_all_param_values [as 别名]
def train_round(num_epochs, network, valid_num, train_fn, val_fn, classn, X_train, a_train, y_train, X_test, a_test, y_test):
print("Starting training...");
print("TrLoss\tVaLoss\tAUC\tCMatrix0\tCMatrix1\tCMatrix2\tEpochs\tTime");
start_time = time.time();
for epoch in range(num_epochs+1):
train_err = 0;
train_batches = 0;
for batch in iterate_minibatches(X_train, a_train, y_train, BatchSize, shuffle = True):
inputs, augs, targets = batch;
inputs = data_aug(inputs, mu, sigma);
train_err += train_fn(inputs, augs, targets);
train_batches += 1;
train_err = train_err / train_batches;
if epoch % 1 == 0:
# And a full pass over the validation data:
test_err, _, _, _, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test);
tpos0, tneg0, fpos0, fneg0 = confusion_matrix(Or, Tr, 0.4);
tpos1, tneg1, fpos1, fneg1 = confusion_matrix(Or, Tr, 0.5);
tpos2, tneg2, fpos2, fneg2 = confusion_matrix(Or, Tr, 0.6);
val_auc = auc_roc(Or, Tr);
# Then we print the results for this epoch:
print("{:.4f}\t{:.4f}\t{:.4f}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}/{}/{}\t{}/{}\t{:.3f}".format(
train_err, test_err, val_auc,
tpos0, tneg0, fpos0, fneg0,
tpos1, tneg1, fpos1, fneg1,
tpos2, tneg2, fpos2, fneg2,
epoch+1, num_epochs, time.time()-start_time));
start_time = time.time();
if epoch % 10 == 0:
param_values = layers.get_all_param_values(network);
pickle.dump(param_values, open(model_dump + "_e{}_cv{}.pkl".format(epoch, valid_num), 'w'));
if epoch == 15:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 50:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
if epoch == 100:
LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));