180304 keras中图像化查看模型训练过程中的acc+loss+val_acc+val_loss
原创
©著作权归作者所有:来自51CTO博客作者GuokLiu的原创作品,请联系作者获取转载授权,否则将追究法律责任
# define the function
def training_vis(hist):
loss = hist.history['loss']
val_loss = hist.history['val_loss']
acc = hist.history['acc'] # new version => hist.history['accuracy']
val_acc = hist.history['val_acc'] #=> hist.history['val_accuracy']
# make a figure
fig = plt.figure(figsize=(8,4))
# subplot loss
ax1 = fig.add_subplot(121)
ax1.plot(loss,label='train_loss')
ax1.plot(val_loss,label='val_loss')
ax1.set_xlabel('Epochs')
ax1.set_ylabel('Loss')
ax1.set_title('Loss on Training and Validation Data')
ax1.legend()
# subplot acc
ax2 = fig.add_subplot(122)
ax2.plot(acc,label='train_acc')
ax2.plot(val_acc,label='val_acc')
ax2.set_xlabel('Epochs')
ax2.set_ylabel('Accuracy')
ax2.set_title('Accuracy on Training and Validation Data')
ax2.legend()
plt.tight_layout()
# train the model
hist = model.fit(...)
# call the function
training_vis(hist)