简体   繁体   中英

Keras: model.evaluate() on training and val set differ from the acc and val_acc after last training epoch

After the last training epoch, I get this output:

Epoch 100/100
89254/89254 - 24s - loss: 0.1935 - acc: 0.9281 - val_loss: 0.2182 - val_acc: 0.9219

But the problem is, once I conduct model.evaluate() on training data and validation data, I get different results:

Train accuracy: 0.929661
Validation accuracy: 0.921859

How does this make sense? And why does parameter batch_size exist for the model.evaluate() function despite test mode? https://keras.io/models/model/#evaluate If I have trained the model in batches, would I need to define the batch size for test mode as well?

Of course it makes sense, to start, any metric/loss produced in the training set on the progress bar is computed as a running mean over training batches, where the weights are changing due to gradient descent. This means that training metrics will never match the ones computed with model.evaluate() , as in that case weights are constant and not changing.

About validation metrics, they do match, its just that the keras progress bar prints only four significant digits, and you printed more.

About batch size, I already commented that basically it has been answered here . Keras uses batches because you cannot make a prediction on a whole dataset at a time, that would probably use too much memory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM