Python/Keras - 如何访问每个纪元预测? [英] Python/Keras - How to access each epoch prediction?

查看:18
本文介绍了Python/Keras - 如何访问每个纪元预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Keras 来预测时间序列.作为标准,我使用 20 个时代.我想通过对 20 个 epoch 中的每一个进行预测来检查我的模型是否学习良好.

I'm using Keras to predict a time series. As standard I'm using 20 epochs. I want to check if my model is learning well, by predicting for each one of the 20 epochs.

通过使用 model.predict() 我在所有时期中只得到一个预测(不确定 Keras 如何选择它).我想要所有的预测,或者至少 10 个最好的.

By using model.predict() I'm getting only one prediction among all epochs (not sure how Keras selects it). I want all predictions, or at least the 10 best.

有人知道如何帮助我吗?

Would anyone know how to help me?

推荐答案

我觉得这里有点混乱.

一个时期只在训练神经网络时使用,所以当训练停止时(在这种情况下,在第 20 个时期之后),那么权重对应于在最后一个时期计算的权重.

An epoch is only used while training the neural network, so when training stops (in this case, after the 20th epoch), then the weights correspond to the ones computed on the last epoch.

Keras 在每个 epoch 之后的训练期间在验证集上打印当前损失值.如果每个 epoch 之后的权重没有被保存,那么它们就会丢失.您可以使用 ModelCheckpoint 回调为每个 epoch 保存权重,然后使用 load_weights 将它们加载回来em> 在您的模型上.

Keras prints current loss values on the validation set during training after each epoch. If the weights after each epoch are not saved, then they are lost. You can save weights for each epoch with the ModelCheckpoint callback, and then load them back with load_weights on your model.

您可以通过对 Callback 进行子类化并调用 predict onon_epoch_end 函数内的模型.

You can compute your predictions after each training epoch by implementing an appropriate callback by subclassing Callback and calling predict on the model inside the on_epoch_end function.

然后要使用它,您需要实例化您的回调,创建一个列表并将其用作 model.fit 的关键字参数回调.

Then to use it, you instantiate your callback, make a list and use it as keyword argument callbacks to model.fit.

这篇关于Python/Keras - 如何访问每个纪元预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆