Keras’s Callback as a Flexible Tool to Monitor Model Statistic

Joel Chao
joelthchao
Published in
1 min readJul 2, 2017

Sometime when we train our model, we not only want to monitor some standard metrics (e.g. loss, accuracy, MSE) but also want to put in a short script to probe the model once in a while. For example, visualization, statistics and custom metrics. Keras’s Callback provides such flexibility to speedup algorithm development.

Let’s build a simple callback to calculate accuracy of multi-class classification every epoch.

And put it in the training loop

You can find that log looks weird. This is a design problem in Keras, it always print progbar in the end, which results in bad format. However, we can do some hacks without touching Keras’s code base to fix it.

I usually use it to make some stats of predictions or do something Keras’s custom metrics cannot achieve. This is my PR to make callback works correctly, however, it is not accepted. Hope this post can help Keras users in using callback.

--

--

Joel Chao
joelthchao

A researcher likes to think interesting deep learning problems.