使用运行统计数据训练 BatchNorm 层是个好主意吗?

发布于 2025-01-16 17:08:11 字数 323 浏览 0 评论 0原文

据我所知,BatchNorm 将在 train 模式下使用批处理统计信息,但使用运行统计信息 (running_mean/running_var) 在eval 模式下。总是在 traineval 模式下使用运行统计数据怎么样?

在我看来,我们毕竟在推理阶段使用了eval模式。为什么我们不在训练阶段一开始就使用 eval 风格 BatchNorm 呢?

As far as I know, BatchNorm will use batch stats in train mode, but use running stats (running_mean/running_var) in eval mode. How about just always use running stats in both train and eval mode?

In my opinion, we use eval mode in inference phase after all. why don't we use eval style BatchNorm from the beginning in the training phase?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2025-01-23 17:08:11

来自 https://pytorch.org/docs/master/ generated/torch.nn.BatchNorm2d.html?highlight=batchnorm2d#torch.nn.BatchNorm2d

[...]在训练期间,该层不断运行对其计算的均值和方差的估计,然后将其用于评估期间的归一化。

我想如果您从未将 BatchNorm 设置为训练,则不会存储任何值(或一些默认值),并且该层将不会针对您的数据进行优化。它类似于线性/卷积层。 “为什么我们不在训练阶段让它们进行评估呢?”嗯,因为我们希望各层能够学习可以在评估模式中使用的东西。

From https://pytorch.org/docs/master/generated/torch.nn.BatchNorm2d.html?highlight=batchnorm2d#torch.nn.BatchNorm2d

[...] during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation.

I imagine if you never set BatchNorm to train, then no values (or some default values) are stored and the layer will not be optimized for your data. It is similar to linear/conv layers. "Why don't we set them to eval in the training phase?" Well because we want the layers to learn something that we can use in evaluation mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文