keras可视化模型训练过程

keras在搭建神经网络模型以及训练神经网络方面,简单又好用,总结几个keras的API使用,持续更新。当然也可以通过keras官网进行学习。https://keras.io/

模型可视化

将模型结构图保存为图片。

from keras.utils import plot_model
plot_model(model, to_file='model.png')

plot_model接收两个可选参数:

show_shapes:指定是否显示输出数据的形状,默认为False
show_layer_names:指定是否显示层名称,默认为True

训练过程可视化

history = model.fit(Xtr_more, Ytr_more, batch_size=batch_size, epochs=50, verbose=1, callbacks=[earlyStopping, mcp_save, reduce_lr_loss], validation_split=0.25)

print(history.history.keys())

fig = plt.figure()
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.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='lower left')
#
fig.savefig('performance.png')

猜你喜欢

转载自blog.csdn.net/m0_37477175/article/details/79131456