美文网首页Python 各类包环境配置 及 使用技巧
Jupyter notebook 实时显示loss和Accura

Jupyter notebook 实时显示loss和Accura

作者: 廿怎么念 | 来源:发表于2020-09-10 21:52 被阅读0次

    点击来源

    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)
    

    相关文章

      网友评论

        本文标题:Jupyter notebook 实时显示loss和Accura

        本文链接:https://www.haomeiwen.com/subject/xjrmektx.html