GroupNorm¶
- class torch.nn.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True, device=None, dtype=None)[source][source]¶
对输入的小批量数据应用 Group Normalization。
此层实现的操作如论文 Group Normalization 中所述
输入通道被分为
num_groups
组,每组包含num_channels / num_groups
个通道。num_channels
必须能被num_groups
整除。均值和标准差在每个组上分别计算。 和 是大小为num_channels
的可学习的每通道仿射变换参数向量,如果affine
为True
。方差通过有偏估计量计算,等同于 torch.var(input, unbiased=False)。此层在训练和评估模式下都使用从输入数据计算的统计信息。
- 参数
- 形状
输入: 其中
输出: (与输入形状相同)
示例
>>> input = torch.randn(20, 6, 10, 10) >>> # Separate 6 channels into 3 groups >>> m = nn.GroupNorm(3, 6) >>> # Separate 6 channels into 6 groups (equivalent with InstanceNorm) >>> m = nn.GroupNorm(6, 6) >>> # Put all 6 channels into a single group (equivalent with LayerNorm) >>> m = nn.GroupNorm(1, 6) >>> # Activating the module >>> output = m(input)