哪些参数应用于提前停止? [英] Which parameters should be used for early stopping?

查看:69
本文介绍了哪些参数应用于提前停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Keras为我的项目训练神经网络。 Keras提供了提前停止的功能。我是否可以知道应该使用哪些参数来避免通过提早停止而使神经网络过度拟合?

I'm training a neural network for my project using Keras. Keras has provided a function for early stopping. May I know what parameters should be observed to avoid my neural network from overfitting by using early stopping?

推荐答案

一旦损失开始增加(换句话说,验证准确性开始降低),早期停止基本上就是停止训练。根据文档,其用法如下;

Early stopping is basically stopping the training once your loss starts to increase (or in other words validation accuracy starts to decrease). According to documents it is used as follows;

keras.callbacks.EarlyStopping(monitor='val_loss',
                              min_delta=0,
                              patience=0,
                              verbose=0, mode='auto')

值取决于您的实现(问题,批处理大小等),但通常防止过度使用;

Values depends on your implementation (problem, batch size etc...) but generally to prevent overfitting I would use;


  1. 监控验证损失(需要使用交叉
    验证或至少使用训练/测试集)通过将 monitor
    参数设置为'val_loss'

  2. min_delta 是一个阈值,用于确定是否在某个时期将损失量化为
    的改善。如果损失的差额小于 min_delta ,则将
    量化为无改善。最好将其保留为0,因为当损失加剧时我们会对
    感兴趣。

  3. 耐心参数代表数字在损失开始增加(停止改善)之前停止。
    这取决于您的实现,如果您使用非常小的批次
    大学习率您的损失之字形(准确度会更高),因此最好设置一个
    大的耐心参数。如果您使用大批量
    学习率
    ,则损失会更平稳,因此您可以使用小
    耐心参数。无论哪种方式,我都将其保留为2,以便让
    给模型更多的机会。

  4. verbose 决定要处理的内容打印,将其保留为默认值(0)。

  5. mode 参数取决于所监视数量
    的方向是它应该在减少或增加),因为我们可以监控损失,因此可以使用 min 。但是让我们留给keras
    处理,然后将其设置为 auto

  1. Monitor the validation loss (need to use cross validation or at least train/test sets) by setting the monitor argument to 'val_loss'.
  2. min_delta is a threshold to whether quantify a loss at some epoch as improvement or not. If the difference of loss is below min_delta, it is quantified as no improvement. Better to leave it as 0 since we're interested in when loss becomes worse.
  3. patience argument represents the number of epochs before stopping once your loss starts to increase (stops improving). This depends on your implementation, if you use very small batches or a large learning rate your loss zig-zag (accuracy will be more noisy) so better set a large patience argument. If you use large batches and a small learning rate your loss will be smoother so you can use a smaller patience argument. Either way I'll leave it as 2 so I would give the model more chance.
  4. verbose decides what to print, leave it at default (0).
  5. mode argument depends on what direction your monitored quantity has (is it supposed to be decreasing or increasing), since we monitor the loss, we can use min. But let's leave keras handle that for us and set that to auto

因此,我将使用类似的方法并通过绘制有无提前停止的错误损失来进行实验。

So I would use something like this and experiment by plotting the error loss with and without early stopping.

keras.callbacks.EarlyStopping(monitor='val_loss',
                              min_delta=0,
                              patience=2,
                              verbose=0, mode='auto')






对于回调的工作方式可能含糊不清,我将尝试解释更多。在模型上调用 fit(... callbacks = [es])后,Keras会调用给定的回调对象预定的函数。这些函数可以称为 on_train_begin on_train_end on_epoch_begin on_epoch_end on_batch_begin on_batch_end 。在每个时期结束时调用提前停止回调,将最佳监视值与当前监视值进行比较,并在条件满足时停止(观察最佳监视值以来已经过去了多少个时期,这不仅仅是耐心参数,两者之间的差最后一个值大于min_delta等。)。


For possible ambiguity on how callbacks work, I'll try to explain more. Once you call fit(... callbacks=[es]) on your model, Keras calls given callback objects predetermined functions. These functions can be called on_train_begin, on_train_end, on_epoch_begin, on_epoch_end and on_batch_begin, on_batch_end. Early stopping callback is called on every epoch end, compares the best monitored value with the current one and stops if conditions are met (how many epochs have past since the observation of the best monitored value and is it more than patience argument, the difference between last value is bigger than min_delta etc..).

@BrentFaust在评论中指出,模型的训练将一直持续到满足提前停止条件或时期参数为止(默认值= 10)满足 fit()中的要求。设置提早停止回调不会使模型超出其 epochs 参数进行训练。因此,使用较大的 epochs 值调用 fit()函数将从Early Stopping回调中受益更多。

As pointed by @BrentFaust in comments, model's training will continue until either Early Stopping conditions are met or epochs parameter (default=10) in fit() is satisfied. Setting an Early Stopping callback will not make the model to train beyond its epochs parameter. So calling fit() function with a larger epochs value would benefit more from Early Stopping callback.

这篇关于哪些参数应用于提前停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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