keras: Keras Progbar Logger is not working as expected
When using model.fit_generator, the progress-bar does not work as expected.
As noted on StackOverflow, the following verbosity levels exist (which should be explained in the documentation):
- 0: No logging
- 1: Displaying a progress-bar for each batch
- 2: Displaying one line per epoch
Verbosity-Modes 0 and 2 work as expected, but mode 1 (the default mode) creates the following output:
Epoch 2/100
64/50000 [..............................] - ETA: 323s - loss: 2.3547 - acc: 0.0625
128/50000 [..............................] - ETA: 181s - loss: 2.3319 - acc: 0.0781
192/50000 [..............................] - ETA: 133s - loss: 2.3233 - acc: 0.1042
256/50000 [..............................] - ETA: 110s - loss: 2.3243 - acc: 0.1055
384/50000 [..............................] - ETA: 86s - loss: 2.3267 - acc: 0.0990
512/50000 [..............................] - ETA: 73s - loss: 2.3213 - acc: 0.1094
640/50000 [..............................] - ETA: 66s - loss: 2.3184 - acc: 0.1109
704/50000 [..............................] - ETA: 63s - loss: 2.3188 - acc: 0.1080
832/50000 [..............................] - ETA: 59s - loss: 2.3177 - acc: 0.1058
960/50000 [..............................] - ETA: 56s - loss: 2.3176 - acc: 0.1031
1088/50000 [..............................] - ETA: 53s - loss: 2.3146 - acc: 0.1048
I already identified the problem in the source-code. It uses \b
and \r
both, which does not work as expected on Windows and Ubuntu 16.04 with PyCharm 2016.3.3. I was able to fix this issue, by simply removing line 257 (sys.stdout.write('\b' * prev_total_width)
) because \r
is a carriage return to the start of the line anyway. I’ve also tested this on Linux and removing line 257 does not break existing functionality.
Is there a reason, why this additional \b
exists? Is it required on Mac? If not, I would file a pull-request to remove that line and fix the progress-bar output on Windows.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 13
- Comments: 55 (5 by maintainers)
Commits related to this issue
- Fixed ProgBar-Logger by removing \b call, because it prevents \r from working correctly. See https://github.com/fchollet/keras/issues/5906 — committed to apacha/keras by apacha 7 years ago
I don’t know if this is related, but I was getting output like this from keras. I’m currently attempting to upgrade versions of keras cudatoolkit and tensorflow to see if that has any effect
@kotoroshinoto I had the exact same issue. After I removed tqdm import, everything works good again.
https://github.com/bstriner/keras-tqdm
^ in case you were wondering what I was talking about
I am getting a similar issue in jupyter notebooks right now
Manged to fix the problem by making the terminal window bigger
The solution of @ibutenko did not work for me unfortunately, however, I found a fix which did not need any modification of sources: install
ipykernel
and import it in your code:pip install ipykernel
Thenimport ipykernel
In fact, in the Keras generic_utils.py file, one probematic line was (for me):
And, the value self._dynamic_display was initiated such as:
So, loading
ipykernel
added it tosys.modules
and fixed the problem for me.@QRiner This fixed my issue. I commented out
import tqdm from tqdm
and the progress bar behavior went back to normal.I got output very similar to @kotoroshinoto fitting models in a Jupyter notebook. I installed keras-tqdm, and it worked perfectly. In your fit function, set
verbose=0
, andcallbacks=[TQDMNotebookCallback()]
.My fix is the following:
Comment out lines 302 to 306 of generic_utils.py, and replace them with a print of the \r character, like so:
This produces the expected behavior for me: Running
nohup myprogram.py &
and thentail -f nohup.out
shows the progress bar moving rightward at the bottom line of the terminal, instead of taking up 100s or 1000s of lines as described above.Getting same thing with keras 2.0.8 in a notebook top
I’ve got this same issue on windows w/ jupyter, except on windows chrome it produces output like this: https://i.imgur.com/Iko46QP.png
On firefox on linux the same issue is happening, but firefox does not render the “\b” character
can confirm that deleting the line @apacha mentions fixes the issue
For who is getting this error in new keras or in google colab, try adding iPython:
I’m seeing this behaviour with keras 2.0.8 in a jupyter notebook
@soomiles I’m in the same boat, I made the PR so I wouldn’t have to add that line to TF everytime I clean install it, however it’s not being included in the latest TF releases lol. Not sure what’s going on, I might open an issue
Edit: Opened issue here: https://github.com/tensorflow/tensorflow/issues/38883
I have updated Keras generic_utils.py as follows to make it work
# sys.stdout.write(bar) # <<<<<<<<<<<<<< Comment
…sys.stdout.write(bar + info) # <<<<<<<<<<<<<< Add
# sys.stdout.write(info) # <<<<<<<<<<<<<< Comment
sys.stdout.flush()
`` I don’t know why this is happening though… Odd.As recommended by @juharris, tqdm actually looks very much like the thing needed here to get rid of the solution that is currently employed which does not work on every system.
Apparently not… My PR was rejected. And the maintainers constantly ignore this for 5 months now. 😡
But you can monkey-patch your installation by searching generic_utils.py in your python installation folder and comment one line as described above.
I had the same problem as @kotoroshinoto, on Spyder 4.1.1 and TF 2.1.0.
I solved the problem by increasing the Progbar update interval to ~0.5s.
tf.keras.utils.Progbar(target, stateful_metrics=metrics_names, interval=0.5)
I’ve also fixed the issue reported by @kotoroshinoto by removing tqdm import and restarting the kernel.
I was getting a weird progress bar in pycharm in the keras version 2.1.3. But it is working fine with the keras that come along with tensorflow,the keras version inside it is version 2.0.8-tf. The weird progress bar prints a new progress bar in a new line for each batch processed. So I was getting 1000+ bars for a single epoch processed as I had 1000+ batches to be fed as input. I changed the Line no:339: from
sys.stdout.write('\n')
tosys.stdout.write('\r')
and it fixed the issue. Is this a valid fix that works for every platform? Should I send a Pull request?Tried this fix on the newest Keras 2.0.2 version and something seems to have changed, because if I remove line 257 now, the output resembles to the following
which is even worse than printing one entry per line.
Update: Hmm… getting this thing now in Keras 1.2.2 too. Check, if this new behavior might be a PyCharm bug.