Keras + TensorFlow Realtime training chart

前端 未结 2 1084
误落风尘
误落风尘 2021-02-04 04:54

I have the following code running inside a Jupyter notebook:

# Visualize training history
from keras.models import Sequential
from keras.layers import Dense
impo         


        
相关标签:
2条回答
  • 2021-02-04 05:23

    Keras comes with a callback for TensorBoard.

    You can easily add this behaviour to your model and then just run tensorboard on top of the logging data.

    callbacks = [TensorBoard(log_dir='./logs')]
    result = model.fit(X, Y, ..., callbacks=callbacks)
    

    And then on your shell:

    tensorboard --logdir=/logs
    

    If you need it in your notebook, you can also write your own callback to get metrics while training:

     class LogCallback(Callback):
    
        def on_epoch_end(self, epoch, logs=None):
            print(logs["train_accuracy"])
    

    This would get the training accuracy at the end of the current epoch and print it. There's some good documentation around it on the official keras site.

    0 讨论(0)
  • 2021-02-04 05:26

    There is livelossplot Python package for live training loss plots in Jupyter Notebook for Keras (disclaimer: I am the author).

    from livelossplot import PlotLossesKeras
    
    model.fit(X_train, Y_train,
              epochs=10,
              validation_data=(X_test, Y_test),
              callbacks=[PlotLossesKeras()],
              verbose=0)
    

    To see how does it work, look at its source, especially this file: https://github.com/stared/livelossplot/blob/master/livelossplot/outputs/matplotlib_plot.py (from IPython.display import clear_output and clear_output(wait=True)).

    A fair disclaimer: it does interfere with Keras output.

    0 讨论(0)
提交回复
热议问题