25

I've just started using Keras. The sample I'm working on has a model and the following snippet is used to run the model

from sklearn.preprocessing import LabelBinarizer
label_binarizer = LabelBinarizer()
y_one_hot = label_binarizer.fit_transform(y_train)

model.compile('adam', 'categorical_crossentropy', ['accuracy'])
history = model.fit(X_normalized, y_one_hot, nb_epoch=3, validation_split=0.2)

I get the following response:

Using TensorFlow backend. Train on 80 samples, validate on 20 samples Epoch 1/3

32/80 [===========>..................] - ETA: 0s - loss: 1.5831 - acc:
0.4062 80/80 [==============================] - 0s - loss: 1.3927 - acc:
0.4500 - val_loss: 0.7802 - val_acc: 0.8500 Epoch 2/3

32/80 [===========>..................] - ETA: 0s - loss: 0.9300 - acc:
0.7500 80/80 [==============================] - 0s - loss: 0.8490 - acc:
0.8000 - val_loss: 0.5772 - val_acc: 0.8500 Epoch 3/3

32/80 [===========>..................] - ETA: 0s - loss: 0.6397 - acc:
0.8750 64/80 [=======================>......] - ETA: 0s - loss: 0.6867 - acc:
0.7969 80/80 [==============================] - 0s - loss: 0.6638 - acc:
0.8000 - val_loss: 0.4294 - val_acc: 0.8500

The documentation says that fit returns

A History instance. Its history attribute contains all information collected during training.

Does anyone know how to interpret the history instance?

For example, what does 32/80 mean? I assume 80 is the number of samples but what is 32? ETA: 0s ??

2 Answers 2

22

ETA = Estimated Time of Arrival.

80 is the size of your training set, 32/80 and 64/80 mean that your batch size is 32 and currently the first batch (or the second batch respectively) is being processed.

loss and acc refer to the current loss and accuracy of the training set. At the end of each epoch your trained NN is evaluated against your validation set. This is what val_loss and val_acc refer to.

The history object returned by model.fit() is a simple class with some fields, e.g. a reference to the model, a params dict and, most importantly, a history dict. It stores the values of loss and acc (or any other used metric) at the end of each epoch. For 2 epochs it will look like this:

{
    'val_loss': [16.11809539794922, 14.12947562917035],
    'val_acc': [0.0, 0.0],
    'loss': [14.890108108520508, 12.088571548461914],
    'acc': [0.0, 0.25]
}

This comes in very handy if you want to visualize your training progress.

Note: if your validation loss/accuracy starts increasing while your training loss/accuracy is still decreasing, this is an indicator of overfitting.

Note 2: at the very end you should test your NN against some test set that is different from you training set and validation set and thus has never been touched during the training process.

6
  • Question: when batches are being processed, loss keep updating on. Now, tell me if the loss is evalauted over the entire dataset or just on the batch. TIA.
    – CKM
    Commented Aug 29, 2019 at 15:41
  • @chandresh as far as I know it's a running average loss, i.e. the loss of the entire dataset progressed so far.
    – sebrockm
    Commented Aug 29, 2019 at 17:21
  • Regarding the 80 value, it should be equivalent to the training data set size. However, I am getting a value of '4/4' in my output with keras in R. However, my training data set has a sample size of 113. Am I misinterpreting the second number after the dash?
    – pdhami
    Commented May 10, 2022 at 17:05
  • 80 is not the size of the training set. It is actually the number of batches. So, the size of the training set is 80 * batch_size. If the batch_size is 64, then the size of training set is 80 * 64. The batch_size is not given in the output.
    – ibilgen
    Commented Oct 19, 2022 at 15:37
  • @ibilgen I haven't been using keras for about 2 years now, so I cannot tell how it is now. But back when I wrote this answer, 80 definitely was the training set size. Maybe they changed the output meanwhile to show the number of batches instead?
    – sebrockm
    Commented Oct 20, 2022 at 10:45
10

32 is your batch size. 32 is the default value that you can change in your fit function if you wish to do so.

After the first batch is trained Keras estimates the training duration (ETA: estimated time of arrival) of one epoch which is equivalent to one round of training with all your samples.

In addition to that you get the losses (the difference between prediction and true labels) and your metric (in your case the accuracy) for both the training and the validation samples.

8
  • do you what acc:0.4062 80/80 means too? acc = accuracy? 80/80 80 correct out of 80? Wouldn't that mean acc = 1.0? Is there a reference link to the meaning of the output anywhere?
    – SeanJ
    Commented Sep 14, 2017 at 12:10
  • 80/80 means "80 samples from a total of 80 samples" have been trained. Therefore the first entry that you see is 32/80 which says: "32 of a total of 80 samples". The accuracy in turn is calculated from the values that your network at this point predicts vs the actual values that you have provided in form of your labels.
    – petezurich
    Commented Sep 14, 2017 at 12:12
  • Your question regarding the meaning of the output is kind of a broader question and I respectfully recommend that you look into one of the many courses that teach the basics, i.e. this one from Jeremy Howard, which is very accessible.
    – petezurich
    Commented Sep 14, 2017 at 12:17
  • 1
    @petezurick thanks! However, I'm not looking for the meaning of accuracy etc. rather just what the abbreviations mean, (coming from Tensorflow background). I would have thought there would be a page explaining what a history output is. Thanks for the link!
    – SeanJ
    Commented Sep 14, 2017 at 12:24
  • 1
    answer is good but incomplete. No reference and val_loss: val_acc not described...
    – SeanJ
    Commented Sep 16, 2017 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.