【问题标题】:Plot Loss vs epochs History for test and training set绘制测试和训练集的损失与历元历史
【发布时间】:2021-03-20 18:08:26
【问题描述】:

我正在使用 TensorFlow 2.4.0 和 Keras,我想为测试和训练集绘制 Loss vs epochs History。我在使用 TensorFlow 1.15 时能够做到这一点,使用下面的代码但是当尝试将其转移到新版本时它不起作用

 model.fit(X2_train ,y2_train, epochs =100, batch_size = 32)
plt.subplot(1,1,1)
plt.plot(model.history.history['loss'])
plt.plot(model.history.history['val_loss'])
plt.title('Loss function of CNN Model')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper right')
plt.ylim(0,200)
plt.grid()
plt.tight_layout()
plt.subplots_adjust(left=0.0, bottom=0.0, right=2.0, top=0.8, wspace=0.2, hspace=0.2)
plt.show()

【问题讨论】:

  • 不清楚您的主要问题是什么。该代码在 tf 1 中有效,但在 tf 2 中无效?给出一些可重现的代码。
  • 是的,它在 tf 1 中工作,而不是在 tf 2 中
  • 提供的信息不充分。您可以共享独立代码来复制您的问题吗?以便我们可以尽力帮助您。谢谢!
  • 这可能是同一个问题here 或者我认为问题是您在model.compile( metrics=["ACC"]) 中定义为度量标准,就像这样post

标签: tensorflow machine-learning keras plot loss


【解决方案1】:

感谢answer,您可以使用history.history 的所有数据集的历史可用指标绘制图表:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(X_train, y_train, nb_epoch=10, validation_data=(X_test, y_test), shuffle=True)

...

pd.DataFrame(history.history).plot(figsize=(8,5))
plt.show()

您也可以保存/记录它。有很好的解决方法here

【讨论】:

    猜你喜欢
    • 2022-12-21
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2021-02-07
    相关资源
    最近更新 更多