【发布时间】: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 中
-
提供的信息不充分。您可以共享独立代码来复制您的问题吗?以便我们可以尽力帮助您。谢谢!
标签: tensorflow machine-learning keras plot loss