快捷方式

GroupNorm

class torch.nn.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True, device=None, dtype=None)[source][source]

对输入的小批量数据应用 Group Normalization。

此层实现的操作如论文 Group Normalization 中所述

y=xE[x]Var[x]+ϵγ+βy = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta

输入通道被分为 num_groups 组,每组包含 num_channels / num_groups 个通道。num_channels 必须能被 num_groups 整除。均值和标准差在每个组上分别计算。γ\gammaβ\beta 是大小为 num_channels 的可学习的每通道仿射变换参数向量,如果 affineTrue。方差通过有偏估计量计算,等同于 torch.var(input, unbiased=False)

此层在训练和评估模式下都使用从输入数据计算的统计信息。

参数
  • num_groups (int) – 将通道分成的组数

  • num_channels (int) – 输入中预期的通道数

  • eps (float) – 为数值稳定性添加到分母的值。默认值:1e-5

  • affine (bool) – 一个布尔值,当设置为 True 时,此模块具有可学习的每通道仿射参数,初始化为 1(对于权重)和 0(对于偏差)。默认值:True

形状
  • 输入: (N,C,)(N, C, *) 其中 C=num_channelsC=\text{num\_channels}

  • 输出: (N,C,)(N, C, *) (与输入形状相同)

示例

>>> 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)

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得解答

查看资源