AttributeError:“Model”对象没有属性“epoch”Keras

2024-09-28 01:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我将在keras中使用一个基于完全连接层(https://blog.keras.io/building-autoencoders-in-keras.html)的简单自动编码器中给出的步骤

wiki_autoencoder.fit(wiki_train, wiki_train,
                epochs=100,
                batch_size=256,
                shuffle=True,
                validation_data=(wiki_test, wiki_test))  

经过培训和交叉验证。绘制结果会产生如下误差:

^{pr2}$

我尝试的第二个结果是:找不到可以放入legend的标签句柄。然而,绘图是生成的。我怎么解决这个问题

enter image description here

plt.plot(wiki_autoencoder.history.history['val_loss'], 'r', wiki_autoencoder.history.history['loss'], 'bo')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()

Tags: httpsiotestwikitrainpltbloghistory
2条回答

您需要正确定义范围,因为您在range()中使用了未定义的时期。根据您的要求,您可以使用除100以外的任何其他号码。在

epochs = range(100)

实际上,你可以从历史对象中找到时代。在

epochs = wiki_autoencoder.history.epoch

这将为您提供模型培训的时代。在

相关问题 更多 >

    热门问题