绘制模型训练收敛曲线

2019-06-12  本文已影响0人  _龙雀
from tensorflow.python.keras.models import Model, Sequential
model = Model()
model_trained = model.fit()
%matplotlib inline   #jupyter notebook 中显示
import matplotlib
matplotlib.use('ggplot') #绘图风格设置
import matplotlib.pyplot as plt

# Plot accuracy
plt.subplot(211)
plt.plot(model_trained.history['acc'])
plt.plot(model_trained.history['val_acc'])
plt.title('Model Accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'], loc='upper left')

# Plot loss
plt.subplot(212)
plt.plot(model_trained.history['loss'])
plt.plot(model_trained.history['val_loss'])
plt.title('Model Loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'], loc='upper right')

plt.show()

plt.tight_layout(h_pad=1.0)
plt.savefig('./output/history-graph.png')

print(str(model_trained.history['val_acc'][-1])[:6] +
      "(max: " + str(max(model_trained.history['val_acc']))[:6] + ")")
print("Done.")
上一篇 下一篇

猜你喜欢

热点阅读