How it looks
Introduction
Live training loss plot in Jupyter Notebook for Keras, PyTorch and other frameworks. An open-source Python package by Piotr Migdał, Bartłomiej Olechno and others. Open for collaboration! (Some tasks are as simple as writing code docstrings, so - no excuses! :))
Installation
# 打开虚拟环境
pip install livelossplot
To get the newest one from this repo (note that we are in the alpha stage, so there may be frequent updates), type:
pip install git+git://github.com/stared/livelossplot.git
PlotLosses for a generic API.
from livelossplot import PlotLosses
from time import sleep
...
plotlosses = PlotLosses()
# begin loop:
plotlosses.update({'acc': 0.7, 'val_acc': 0.4, 'loss': 0.9, 'val_loss': 1.1})
plotlosses.send() # draw, update logs, etc
sleep(.01)
# end loop
More Examples
Look at notebook files with full working examples:
- keras.ipynb - a Keras callback
- minimal.ipynb - a bare API, to use anywhere
- bokeh.ipynb - a bare API, plots with Bokeh (open it in Colab to see the plots)
- pytorch.ipynb - a bare API, as applied to PyTorch
- 2d_prediction_maps.ipynb - example of custom plots - 2d prediction maps (0.4.1+)
- poutyne.ipynb - a Poutyne callback (Poutyne is a Keras-like framework for PyTorch)
- torchbearer.ipynb - an example using the built in functionality from torchbearer (torchbearer is a model fitting library for PyTorch)
- neptune.py and neptune.ipynb - a Neptune.AI
- matplotlib.ipynb - a Matplotlib output example
- various_options.ipynb - an extended API for metrics grouping and custom outputs
Concrete Example: Matplotlib output
%matplotlib inline
from time import sleep
from matplotlib import pyplot as plt
import numpy as np
from livelossplot import PlotLosses
from livelossplot.outputs import MatplotlibPlot
def test_output(outputs):
groups = {'acccuracy': ['acc', 'val_acc'], 'log-loss': ['loss', 'val_loss']}
plotlosses = PlotLosses(groups=groups, outputs=outputs)
for i in range(100):
plotlosses.update({
'acc': 1 - np.random.rand() / (i + 2.),
'val_acc': 1 - np.random.rand() / (i + 0.5),
'loss': 1. / (i + 2.),
'val_loss': 1. / (i + 0.5)
})
plotlosses.send()
sleep(.01)
outputs = [MatplotlibPlot()]
test_output(outputs)
Custom after subplot function
You can replace after subplot function, which operates on suitable group axis.
def custom_after_subplot(ax: plt.Axes, group: str, x_label: str):
"""Make logarithmic scale on loss chart"""
if group == 'log-loss':
ax.loglog()
ax.set_xlabel(x_label)
outputs = [MatplotlibPlot(after_subplot=custom_after_subplot)]
test_output(outputs)