Keras + TensorFlow实时培训图 [英] Keras + TensorFlow Realtime training chart

查看:123
本文介绍了Keras + TensorFlow实时培训图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jupyter笔记本中运行以下代码:

I have the following code running inside a Jupyter notebook:

# Visualize training history
from keras.models import Sequential
from keras.layers import Dense
import matplotlib.pyplot as plt
import numpy
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, kernel_initializer='uniform', activation='relu'))
model.add(Dense(8, kernel_initializer='uniform', activation='relu'))
model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
history = model.fit(X, Y, validation_split=0.33, epochs=150, batch_size=10, verbose=0)
# list all data in history
print(history.history.keys())
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()

该代码收集历元历史记录,然后显示进度历史记录.

The code collects epochs history, then displays the progress history.

问::如何在训练时更改图表,以便实时查看更改?

Q: How can I make the chart change while training so I can see the changes in real time?

推荐答案

livelossplot Python程序包Jupyter Notebook for Keras中的实时训练损失图(免责声明:我是作者).

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/core.py (from IPython.display import clear_output and clear_output(wait=True)).

一个合理的免责声明:它确实会干扰Keras的输出.

A fair disclaimer: it does interfere with Keras output.

这篇关于Keras + TensorFlow实时培训图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆