예제 #1
0
reduce_lr = ReduceLROnPlateau(monitor="val_loss", patience=10, verbose=1)
reduce_lr.set_model(model)
reduce_lr.on_train_begin()

tensorboard = TensorBoard(log_dir="logs/")
tensorboard.set_model(model)
tensorboard.on_train_begin()

epochs = 3
train_logs_dict = {}
test_logs_dict = {}
for epoch in range(epochs):
    training_acc, testing_acc, training_loss, testing_loss = [], [], [], []
    print("\nStart of epoch %d" % (epoch + 1, ))
    # Iterate over the batches of the dataset.
    modelcheckpoint.on_epoch_begin(epoch)
    earlystop.on_epoch_begin(epoch)
    reduce_lr.on_epoch_begin(epoch)
    tensorboard.on_epoch_begin(epoch)
    for x_batch_train, y_batch_train in get_batch(batch_size, x_train,
                                                  y_train):

        train_loss, train_accuracy = model.train_on_batch(
            x_batch_train, y_batch_train)
        training_acc.append(train_accuracy)
        training_loss.append(train_loss)

    for x_batch_test, y_batch_test in get_batch(batch_size, x_test, y_test):

        test_loss, test_accuracy = model.test_on_batch(x_batch_test,
                                                       y_batch_test)