gpt4 book ai didi

machine-learning - Batchnorm2d Pytorch - 为什么将 channel 数传递给 batchnorm?

转载 作者:行者123 更新时间:2023-12-04 11:42:53 34 4
gpt4 key购买 nike

为什么我需要将之前的 channel 数传递给 batchnorm? batchnorm 应该对批处理中的每个数据点进行归一化,为什么它需要有 channel 数呢?

最佳答案

批量归一化具有可学习的参数,因为它包括仿射变换。

来自 nn.BatchNorm2d 的文档:

BatchNorm Formular

The mean and standard-deviation are calculated per-dimension over the mini-batches and γ and β are learnable parameter vectors of size C (where C is the input size). By default, the elements of γ are set to 1 and the elements of β are set to 0.



由于范数是按每个 channel 计算的,参数 γ 和 β 是大小为 num_channels(每个 channel 一个元素)的向量,这会导致每个 channel 的单独缩放和偏移。与 PyTorch 中的任何其他可学习参数一样,它们需要以固定大小创建,因此您需要指定 channel 数

batch_norm = nn.BatchNorm2d(10)

# γ
batch_norm.weight.size()
# => torch.Size([10])

# β
batch_norm.bias.size()
# => torch.Size([10])

注意:设置 affine=False不使用任何参数,也不需要 channel 数,但它们仍然是必需的,以便具有一致的接口(interface)。

关于machine-learning - Batchnorm2d Pytorch - 为什么将 channel 数传递给 batchnorm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62041724/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com