InstanceNorm2D¶

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

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

DataLayout: NCHW [batch, in_channels, 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

Unexpected indentation.

numerical stability. Default is 1e-5.

Block quote ends without a blank line; unexpected unindent.

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

Unexpected indentation.

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.

Block quote ends without a blank line; unexpected unindent.

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.

Definition list ends without a blank line; unexpected unindent.

data_format(str, optional): Specify the input data format, could be “NCHW”. Default: NCHW. name(str, optional): Name for the InstanceNorm, default is None. For more information, please refer to Name..

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

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

Returns:

None.

Examples:

import paddle

x = paddle.rand((2, 2, 2, 3))