Jupyter notebook 实时显示loss和Accuracy

点击来源

How it looks

live loss and accuracy.gif

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:

You run examples in Colab.

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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。