且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python/Keras-如何访问每个时期的预测?

更新时间:2023-11-23 09:25:28

我认为这里有些混乱.

仅在训练神经网络时才使用一个历元,因此当训练停止时(在这种情况下,是在第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.