stared / livelossplot

Live training loss plot in Jupyter Notebook for Keras, PyTorch and others
https://p.migdal.pl/livelossplot
MIT License
1.29k stars 143 forks source link

Need to close window every time to proceed ahead with the epoch. #76

Closed ravishk1 closed 4 years ago

ravishk1 commented 4 years ago

Training stops after every epoch completion, need to manually close the window and then only it proceeds with next epoch. Can't it simultaneously plot and proceed to the next epoch?

Thanks for this library btw. :)

stared commented 4 years ago

@ravishk1 Do you run it within Jupyter Notebook?

(As of now, it is not suited for running it from other environments.)

PhilMacKay commented 4 years ago

Hello! If we modify the file livelossplot/core.py on line 30 to specify a figure name (for example, it could be "livelossplot"!), add a plt.clf() right after line 30, and add the keyword block=False in the call to plt.show() on line 71, it would be possible to use Livelossplot from IPython or from a Python script!

I have been using these modifications locally with the Qt5Agg backend for a while and it works well. The call to plt.clf() is somewhat slow, but if an epoch lasts more than a full second, it's not noticeable.

I would gladly make a pull-request if you're interested, I think these small modifications would solve a large part of non-Notebook support!

Edit: I forgot an additional line. Right after plt.show(block=False), we need to add plt.pause(0.001). This tells Matplotlib to wait for 0.001 second and execute the windows events, otherwise the created window will be unresponsive until the loop is finished!

I tried the following code in a Jupyter notebook, in IPython, and in a script file called with python script.py and they all worked. It was slower in a script file, and the windows dissapears as soon as the script is over. To prevent this, you can add a plt.show() right at the end.

import random
import matplotlib.pyplot as plt
from IPython.display import clear_output
from matplotlib import get_backend

print(get_backend())

data = []
for i in range(25):
    data.append(random.random())
    clear_output(wait=True)
    plt.figure("livelossplot", figsize=None)
    plt.clf()
    plt.plot(data)
    plt.show(block=False)
    plt.pause(0.001)
stared commented 4 years ago

Thanks for your comment, @PhilMacKay. I had some time off with livelossplot. But in the last two weeks, we rewrote the library (with @Bartolo1024) and released as 0.5.0. Now it is more modular and it will be easier to make such changes.

As you see, we started targetting non-Jupyter environments, see https://github.com/stared/livelossplot/blob/master/livelossplot/outputs/. We will try to include it in 0.5.1 release, most likely using (for livelossplot) parameters to specify if it is 'jupyter', 'script' or 'server' (only saving plots as files). PRs are welcome! :)

TheDudeFromCI commented 3 years ago

Are there any plans to implement this in the current version of the code? Even with the current version, and setting the mode to 'script', it seems that non-blocking graphs have not yet been added.