如何确定每个时期的Keras训练准确性? [英] How is the training accuracy in Keras determined for every epoch?

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

问题描述

我正在Keras中训练模型,如下所示:

I am training a model in Keras with as follows:

model.fit(Xtrn, ytrn batch_size=16, epochs=50, verbose=1, shuffle=True,
          callbacks=[model_checkpoint], validation_data=(Xval, yval))

拟合输出如下:

model.fit所示,我的批次大小为16,总共有8000个训练样本,如输出所示.因此,据我了解,每16个批次都要进行培训.这也意味着训练针对单个时期进行了500次(即,8000/16 =500)

As shown in the model.fit I have a batch size of 16 and a total of 8000 training samples as shown in the output. So from my understanding, training takes place every 16 batches. Which also means training is ran 500 times for a single epoch (i.e., 8000/16 =500)

因此,让我们来看看输出在Epoch 1/50输出中的训练精度,在本例中为0.9381.我想知道0.9381的训练精度是如何得出的.

So let's take the training accuracy printed in the output for Epoch 1/50, which in this case is 0.9381. I would like to know how is this training accuracy of 0.9381 derived.

是:

  1. 平均值 培训精度是否是每批执行的500次培训的平均值?
  1. Is the mean training accuracy, taken as the average from the 500 times training, performed for every batch?

OR,

  1. 在运行训练程序的500实例中,这是否是最佳(或 max )训练精度?
  1. Is it the best (or max) training accuracy from out of the 500 instances the training procedure is run?

推荐答案

看看Keras中的BaseLogger,他们正在计算运行均值. 对于每个时期,准确性是该时期之前看到的所有批次的平均值.

Take a look at the BaseLogger in Keras where they're computing a running mean. For each epoch the accuracy is the average of all the batches seen before in that epoch.

class BaseLogger(Callback):
    """Callback that accumulates epoch averages of metrics.

    This callback is automatically applied to every Keras model.
    """

    def on_epoch_begin(self, epoch, logs=None):
        self.seen = 0
        self.totals = {}

    def on_batch_end(self, batch, logs=None):
        logs = logs or {}
        batch_size = logs.get('size', 0)
        self.seen += batch_size

        for k, v in logs.items():
            if k in self.totals:
                self.totals[k] += v * batch_size
            else:
                self.totals[k] = v * batch_size

    def on_epoch_end(self, epoch, logs=None):
        if logs is not None:
            for k in self.params['metrics']:
                if k in self.totals:
                    # Make value available to next callbacks.
                    logs[k] = self.totals[k] / self.seen

这篇关于如何确定每个时期的Keras训练准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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