Python lasagne.layers.get_all_param_values() Examples
The following are 30
code examples of lasagne.layers.get_all_param_values().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lasagne.layers
, or try the search function
.
Example #1
Source File: lasagne_net.py From BirdCLEF-Baseline with MIT License | 6 votes |
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 ######################
Example #2
Source File: lasagne_io.py From BirdCLEF-Baseline with MIT License | 6 votes |
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]
Example #3
Source File: AED_train.py From AcousticEventDetection with MIT License | 6 votes |
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!"
Example #4
Source File: deep_conv_ae_spsparse_alt34.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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-5)) / 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 % 5 == 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 > 16: BatchSize = 16;
Example #5
Source File: deep_conv_ae_spsparse_alt28.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'));
Example #6
Source File: deep_conv_ae_spsparse_alt30.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'));
Example #7
Source File: deep_conv_classification_alt58.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #8
Source File: deep_conv_classification_alt48_luad10_skcm10_lr0.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 == 5: LearningRate.set_value(np.float32(0.10*LearningRate.get_value())); if epoch == 25: LearningRate.set_value(np.float32(0.10*LearningRate.get_value())); if epoch == 40: LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
Example #9
Source File: deep_conv_ae_spsparse_alt33.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'));
Example #10
Source File: deep_conv_classification_alt40.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #11
Source File: deep_conv_classification_alt48_only_skcm_t1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #12
Source File: deep_conv_classification_alt48_luad10_skcm10_v1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 == 10: 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()));
Example #13
Source File: deep_conv_ae_spsparse_alt42.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 > 32: BatchSize = 32;
Example #14
Source File: deep_conv_classification_alt51.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #15
Source File: deep_conv_classification_alt63.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #16
Source File: deep_conv_classification_alt30.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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\t\tVaLoss\t\tVaHamm\t\tAUC\t\tCMatrix\t\t\tEpochs\t\tTime"); batchsize = 100; 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, test_ham, _, Pr, Or, Tr = val_fn_epoch(classn, val_fn, X_test, a_test, y_test); tpos, tneg, fpos, fneg = confusion_matrix(Pr, Tr); val_auc = auc_roc(Or, Tr); # Then we print the results for this epoch: print("{:.4f}\t\t{:.4f}\t\t{:.4f}\t\t{:.4f}\t\t{}/{}/{}/{}\t\t{}/{}\t\t{:.3f}".format( train_err, test_err, test_ham, val_auc, tpos, tneg, fpos, fneg, 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 == 6: LearningRate.set_value(np.float32(0.10*LearningRate.get_value())); if epoch == 10: LearningRate.set_value(np.float32(0.10*LearningRate.get_value())); # Return a new set of features. _, _, _, _, train_Or, _ = val_fn_epoch(classn, val_fn, X_train, a_train, y_train); _, _, _, _, test_Or, _ = val_fn_epoch(classn, val_fn, X_test, a_test, y_test); return train_Or, test_Or;
Example #17
Source File: deep_conv_classification_alt48maxp_luad10_luad10in20_brca10x2.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #18
Source File: deep_conv_classification_alt48_luad10_luad10in20_brca10x1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #19
Source File: deep_conv_classification_alt48maxp_luad10_luad10in20_brca10x1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #20
Source File: deep_conv_classification_alt38.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #21
Source File: deep_conv_classification_alt48_luad10_luad10in20_brca10x2.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #22
Source File: deep_conv_ae_spsparse_alt27.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'));
Example #23
Source File: deep_conv_classification_alt48_adeno_prad_t1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #24
Source File: deep_conv_classification_alt41.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #25
Source File: deep_conv_classification_alt62.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #26
Source File: deep_conv_ae_spsparse_alt22.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 it % 10 == 0: param_values = layers.get_all_param_values(network); pickle.dump(param_values, open(filename_model_ae.format(epoch), 'w'));
Example #27
Source File: deep_conv_classification_alt48_luad10in20_brca10.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #28
Source File: deep_conv_classification_lpatch_alt2.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 == 20: 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 == 100: LearningRate.set_value(np.float32(0.10*LearningRate.get_value()));
Example #29
Source File: deep_conv_classification_alt48_only_skcm_t0.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));
Example #30
Source File: deep_conv_classification_alt43.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()));