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
整除。均值和标准差分别在每组内计算。 和 是按通道学习的仿射变换参数向量,如果affine
为True
,它们的大小为num_channels
。方差是使用有偏估计器计算的,相当于 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)