Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras CNN, verbose training progress bar display

Running CNN in Keras. When it starts to run model.fit, it prints progress bar for each batch, like this

progress bar for each batch

Is it possible to display the progress bar for each epoch? Like this

enter image description here

Here is how I am using model.fit(x_train, y_train, nb_epoch = 1, batch_size = 32, verbose=1) I have tried to set verbose to 0 and 2, but there is no progress bar.

Please let me know if you have any thoughts. Many thanks

like image 569
Braidy916 Avatar asked May 15 '17 12:05

Braidy916


1 Answers

I gave a solution (not sure if can work for every case, but worked well for me) in https://stackoverflow.com/a/57475559/9531617. To quote myself:


The problem can be fixed without modifying the sources by simply installing ipykernel and importing it in your code:

pip install ipykernel Then import ipykernel

In fact, in the Keras generic_utils.py file, the probematic line was (in my case):

            if self._dynamic_display:
                sys.stdout.write('\b' * prev_total_width)
                sys.stdout.write('\r')
            else:
                sys.stdout.write('\n')

Where the self._dynamic_display was False, whereas it needed to be True to work properly. But the value self._dynamic_display was initiated such as:

        self._dynamic_display = ((hasattr(sys.stdout, 'isatty') and
                                  sys.stdout.isatty()) or
                                 'ipykernel' in sys.modules)

So, loading ipykerneladded it to sys.modules and fixed the problem for me.

like image 134
Antonin G. Avatar answered Oct 16 '22 06:10

Antonin G.