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

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

问题描述

我正在使用Keras预测时间序列.作为标准,我使用20个纪元. 我想知道我的神经网络对20个纪元中的每个纪元有什么预测.

I'm using Keras to predict a time series. As standard I'm using 20 epochs. I want to know what did my neural network predict 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 select 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在训练期间将当前损耗值打印在验证集上.如果未保存每个时期之后的权重,则它们将丢失.您可以使用 ModelCheckpoint 回调保存每个时期的权重,然后使用 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.

您可以在每个训练时期之后,通过将回调子类化并调用on来实现适当的回调,从而计算您的预测 on_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天全站免登陆