Search code examples
kerasdeep-learninggoogle-colaboratory

Keras fit_generator() does not show accuracy on Colab


I have just moved from my local PC to train a model on Colab.

I think there may be an issue with Colab, as Keras fit_generator() does not tell me the accuracy (only loss). How to make the accuracy shown?

The code can display accuracy on my PC. However, the code on Colab looks like this

# Model Compile
model.compile(optimizer='Adam', loss='categorical_crossentropy')

# Training
nb_epochs = 10
model.fit_generator(
    train_generator,
    steps_per_epoch = train_generator.samples // batch_size,
    validation_data = validation_generator,
    validation_steps = validation_generator.samples // batch_size,
    epochs = nb_epochs
    verbose = 2)

The result does not have an accuracy reported.

Epoch 1/10
 - 48s - loss: 13.6619 - val_loss: 13.9256
Epoch 2/10
 - 48s - loss: 13.6741 - val_loss: 13.7124

I expect the result also shown with acc and loss_acc, like:

Epoch 1/50
 - 791s - loss: 1.1517 - acc: 0.6122 - val_loss: 1.2601 - val_acc: 0.5735

Solution

  • This means you did not specify any metrics during model building, in the model.compile line, you have to specify the accuracy metric for it to show during training:

    model.compile(loss=..., optimizer=..., metrics=["accuracy"])