InstanceNorm

class InstanceNorm(num_channels, eps=1e-05, affine=True, **kwargs)[源代码]

Applies Instance Normalization over a mini-batch of inputs Refer to Instance Normalization

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

The mean and standard-deviation are calculated per-dimension separately for each object in a mini-batch. \(\\gamma\) and \(\\beta\) are learnable affine transform parameters of attr:num_channels if affine is True. Note that InstanceNorm equals using GroupNorm with num_groups = num_channels.

参数
  • num_channels (int) – number of channels expected in input

  • eps – 添加到分母的单个值,增加数值稳定性。默认:1e-5

  • affine – this module has learnable affine parameters (weight, bias) when affine is set to be True.

形状:
  • Input: \((N, C, H, W)\) (now only support NCHW format tensor)

  • Output: \((N, C, H, W)\) (same shape as input)

实际案例

>>> import numpy as np
>>> inp = Tensor(np.arange(2 * 3 * 4 * 4).astype(np.float32).reshape(2, 3, 4, 4))
>>> m = M.InstanceNorm(3)
>>> out = m(inp)
>>> out.numpy().shape
(2, 3, 4, 4)