InstanceNorm3D

class paddle.nn. InstanceNorm3D ( num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format='NCDHW', name=None ) [source]

Create a callable object of InstanceNorm3D. Applies Instance Normalization over a 5D input (a mini-batch of 3D inputs with additional channel dimension) as described in the paper Instance Normalization: The Missing Ingredient for Fast Stylization .

DataLayout: NCDHW [batch, in_channels, D, in_height, in_width]

\(input\) is the input features over a mini-batch.

\[\begin{split}\mu_{\beta} &\gets \frac{1}{HW} \sum_{i=1}^{HW} x_i \qquad &//\ \ mean\ of\ one\ feature\ map\ in\ mini-batch \\ \sigma_{\beta}^{2} &\gets \frac{1}{HW} \sum_{i=1}^{HW}(x_i - \ \mu_{\beta})^2 \qquad &//\ variance\ of\ one\ feature\ map\ in\ mini-batch \\ \hat{x_i} &\gets \frac{x_i - \mu_\beta} {\sqrt{\ \sigma_{\beta}^{2} + \epsilon}} \qquad &//\ normalize \\ y_i &\gets \gamma \hat{x_i} + \beta \qquad &//\ scale\ and\ shift\end{split}\]

Where H means height of feature map, W means width of feature map.

Parameters
  • num_features (int) – Indicate the number of channels of the input Tensor.

  • epsilon (float, optional) – A value added to the denominator for numerical stability. Default is 1e-5.

  • momentum (float, optional) – The value used for the moving_mean and moving_var computation. Default: 0.9.

  • weight_attr (ParamAttr|bool, optional) – The parameter attribute for Parameter scale of instance_norm. If it is set to None or one attribute of ParamAttr, instance_norm will create ParamAttr as weight_attr, the name of scale can be set in ParamAttr. If the Initializer of the weight_attr is not set, the parameter is initialized one. If it is set to False, will not create weight_attr. Default: None. For more information, please refer to ParamAttr .

  • bias_attr (ParamAttr|bool, optional) – The parameter attribute for the bias of instance_norm. If it is set to None or one attribute of ParamAttr, instance_norm will create ParamAttr as bias_attr, the name of bias can be set in ParamAttr. If the Initializer of the bias_attr is not set, the bias is initialized zero. If it is set to False, will not create bias_attr. Default: None. For more information, please refer to ParamAttr .

  • data_format (str, optional) – Specify the input data format, could be “NCDHW”. Default: NCDHW.

  • name (str, optional) – Name for the InstanceNorm, default is None. For more information, please refer to Name .

Shape:
  • x: 5-D tensor with shape: (batch, num_features, dims, height, weight).

  • output: 5-D tensor with same shape as input x.

Returns

None.

Examples

>>> import paddle
>>> paddle.seed(100)
>>> x = paddle.rand((2, 2, 2, 2, 3))
>>> instance_norm = paddle.nn.InstanceNorm3D(2)
>>> instance_norm_out = instance_norm(x)

>>> print(instance_norm_out)
Tensor(shape=[2, 2, 2, 2, 3], dtype=float32, place=Place(cpu), stop_gradient=False,
[[[[[ 0.60520107, -0.67670596, -1.40020907],
    [ 0.46540472, -0.09736639, -0.47771260]],
   [[-0.74365318,  0.63718963, -1.41333199],
    [ 1.44764769, -0.25489071,  1.90842640]]],
  [[[ 1.09773374,  1.49568439, -0.45503727],
    [-1.01755965,  1.08368278, -0.38671401]],
   [[-0.62252384,  0.60490805,  0.13109155],
    [-0.81222630,  0.84286022, -1.96189928]]]],
 [[[[ 0.28014541,  0.91674680,  1.71797717],
    [-0.52062720, -0.74274176, -0.86439967]],
   [[ 0.25707796, -1.23866379,  1.64422870],
    [-1.48577297, -0.13187379,  0.16790220]]],
  [[[-1.49266160,  1.57909954,  0.46455818],
    [-0.14981404,  1.46959865,  0.24957968]],
   [[ 0.25134835, -0.03276967, -0.30318922],
    [ 0.76263177, -1.11345232, -1.68492818]]]]])