Rate this Page

InstanceNorm3d#

classtorch.nn.InstanceNorm3d(num_features,eps=1e-05,momentum=0.1,affine=False,track_running_stats=False,device=None,dtype=None)[source]#

Applies Instance Normalization.

This operation applies Instance Normalizationover a 5D input (a mini-batch of 3D inputs with additional channel dimension) as described in the paperInstance Normalization: The Missing Ingredient for Fast Stylization.

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

The mean and standard-deviation are calculated per-dimension separatelyfor each object in a mini-batch.γ\gamma andβ\beta are learnable parameter vectorsof size C (where C is the input size) ifaffine isTrue.The standard-deviation is calculated via the biased estimator, equivalent totorch.var(input, unbiased=False).

By default, this layer uses instance statistics computed from input data inboth training and evaluation modes.

Iftrack_running_stats is set toTrue, during training thislayer keeps running estimates of its computed mean and variance, which arethen used for normalization during evaluation. The running estimates arekept with a defaultmomentum of 0.1.

Note

Thismomentum argument is different from one used in optimizerclasses and the conventional notion of momentum. Mathematically, theupdate rule for running statistics here isx^new=(1momentum)×x^+momentum×xt\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t,wherex^\hat{x} is the estimated statistic andxtx_t is thenew observed value.

Note

InstanceNorm3d andLayerNorm are very similar, buthave some subtle differences.InstanceNorm3d is appliedon each channel of channeled data like 3D models with RGB color, butLayerNorm is usually applied on entire sample and often in NLPtasks. Additionally,LayerNorm applies elementwise affinetransform, whileInstanceNorm3d usually don’t apply affinetransform.

Parameters
  • num_features (int) –CC from an expected input of size(N,C,D,H,W)(N, C, D, H, W) or(C,D,H,W)(C, D, H, W)

  • eps (float) – a value added to the denominator for numerical stability. Default: 1e-5

  • momentum (Optional[float]) – the value used for the running_mean and running_var computation. Default: 0.1

  • affine (bool) – a boolean value that when set toTrue, this module haslearnable affine parameters, initialized the same way as done for batch normalization.Default:False.

  • track_running_stats (bool) – a boolean value that when set toTrue, thismodule tracks the running mean and variance, and when set toFalse,this module does not track such statistics and always uses batchstatistics in both training and eval modes. Default:False

Shape:

Examples:

>>># Without Learnable Parameters>>>m=nn.InstanceNorm3d(100)>>># With Learnable Parameters>>>m=nn.InstanceNorm3d(100,affine=True)>>>input=torch.randn(20,100,35,45,10)>>>output=m(input)