美文网首页
绘制模型训练收敛曲线

绘制模型训练收敛曲线

作者: _龙雀 | 来源:发表于2019-06-12 17:58 被阅读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.")

相关文章

网友评论

      本文标题:绘制模型训练收敛曲线

      本文链接:https://www.haomeiwen.com/subject/lphrfctx.html