Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras Model.fit Verbose Formatting

I'm running Keras model.fit() in Jupyter notebook, and the output is very messy if verbose is set to 1:

    Train on 6400 samples, validate on 800 samples
    Epoch 1/200
    2080/6400 [========>.....................] - ETA: 39s - loss: 0.4383 - acc: 0.79 
    - ETA: 34s - loss: 0.3585 - acc: 0.84 - ETA: 33s - loss: 0.3712 - acc: 0.84 
    - ETA: 34s - loss: 0.3716 - acc: 0.84 - ETA: 33s - loss: 0.3675 - acc: 0.84 
    - ETA: 33s - loss: 0.3650 - acc: 0.84 - ETA: 34s - loss: 0.3759 - acc: 0.83 
    - ETA: 34s - loss: 0.3933 - acc: 0.82 - ETA: 34s - loss: 0.3985 - acc: 0.82 
    - ETA: 34s - loss: 0.4057 - acc: 0.82 - ETA: 33s - loss: 0.4071 - acc: 0.81 
    ....

As you can see, the ETA, loss, acc outputs kept appending to the log, instead of replacing the original ETA/loss/acc values within the first line, just like how the progress bar works.

How do I fix it it so that only 1 line of progress bar, ETA, loss & acc are shown per epoch? Right now, my cell output has tons of these lines as the training continues.

I'm running Python 3.6.1 on Windows 10, with the following module versions:

jupyter                            1.0.0
jupyter-client                     5.0.1
jupyter-console                    5.1.0
jupyter-core                       4.3.0
jupyterthemes                      0.19.0
Keras                              2.2.0
Keras-Applications                 1.0.2
Keras-Preprocessing                1.0.1
tensorflow-gpu                     1.7.0

Thank you.

like image 532
Mongrel Jedi Avatar asked Dec 01 '25 20:12

Mongrel Jedi


1 Answers

Took me a while to see this but I just added built-in support for keras in tqdm (version >= 4.41.0) so you could do:

from tqdm.keras import TqdmCallback
...
model.fit(..., verbose=0, callbacks=[TqdmCallback(verbose=2)])

This turns off keras' progress (verbose=0), and uses tqdm instead. For the callback, verbose=2 means separate progressbars for epochs and batches. 1 means clear batch bars when done. 0 means only show epochs (never show batch bars).

like image 140
casper.dcl Avatar answered Dec 03 '25 11:12

casper.dcl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!