Ejemplo n.º 1
0
        print(
            "Epoch {0} finished. Total Training Loss: {1}, Driver Loss: {2}, Risk Loss: {3}"
            .format(epoch, train_total_loss, train_driver_loss,
                    train_risk_loss))
        path = os.path.join(save_path, str(epoch))
        os.makedirs(path)
        model.save_parameters(path)

        bar = progressbar.ProgressBar()
        valid_LB = 0.0
        val_LB1 = 0.0
        val_LB2 = 0.0
        for batch in bar(val_batch_order):
            batch_end = min(model.batch_size * (batch + 1), x_valid.shape[0])
            batch_start = model.batch_size * batch
            l1, l2, l3 = model.likelihood(batch_start, batch_end)
            val_total_loss += (l1 + l2 + l3) * (batch_end - batch_start)
            val_driver_loss += l2 * (batch_end - batch_start)
            val_risk_loss += l3 * (batch_end - batch_start)

        val_total_loss /= x_valid.shape[0]
        val_driver_loss /= x_valid.shape[0]
        val_risk_loss /= x_valid.shape[0]

        print("Val loss: {}, Val driver loss: {}, Val Risk Loss: {}".format(
            val_total_loss, val_driver_loss, val_risk_loss))

        ###Classification
        h_train = []
        h_val = []
        for i in range(x_train.shape[0] // model.batch_size + 1):
Ejemplo n.º 2
0
if os.path.isfile(path + "params.pkl"):
    print "Restarting from earlier saved parameters!"
    model.load_parameters(path)
    LB_list = np.load(path + "LB_list.npy")
    epoch = len(LB_list)

if __name__ == "__main__":
    print "iterating"
    while epoch < n_epochs:
        epoch += 1
        start = time.time()
        np.random.shuffle(batch_order)
        LB = 0.

        for batch in batch_order:
            batch_LB = model.update(batch, epoch)
            LB += batch_LB

        LB /= len(batch_order)

        LB_list = np.append(LB_list, LB)
        print "Epoch {0} finished. LB: {1}, time: {2}".format(epoch, LB, time.time() - start)
        np.save(path + "LB_list.npy", LB_list)
        #model.save_parameters(path)

    valid_LB = model.likelihood(x_valid)
    print "LB on validation set: {0}".format(valid_LB)



Ejemplo n.º 3
0
if os.path.isfile(path + "params.pkl"):
    print "Restarting from earlier saved parameters!"
    model.load_parameters(path)
    LB_list = np.load(path + "LB_list.npy")
    epoch = len(LB_list)

if __name__ == "__main__":
    print "iterating"
    while epoch < n_epochs:
        epoch += 1
        start = time.time()
        np.random.shuffle(batch_order)
        LB = 0.

        for batch in batch_order:
            batch_LB = model.update(batch, epoch)
            LB += batch_LB

        LB /= len(batch_order)

        LB_list = np.append(LB_list, LB)
        print "Epoch {0} finished. LB: {1}, time: {2}".format(
            epoch, LB,
            time.time() - start)
        np.save(path + "LB_list.npy", LB_list)
        #model.save_parameters(path)

    valid_LB = model.likelihood(x_valid)
    print "LB on validation set: {0}".format(valid_LB)