instance_norm

paddle.fluid.layers.nn. instance_norm ( input, epsilon=1e-05, param_attr=None, bias_attr=None, name=None ) [source]
Api_attr

Static Graph

Instance Normalization Layer

Can be used as a normalizer function for convolution or fully_connected operations. The required data format for this layer is one of the following:

DataLayout: NCHW [batch, in_channels, in_height, in_width]

Refer to Instance Normalization: The Missing Ingredient for Fast Stylization for more details.

\(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}\]

Note

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

Parameters
  • input (Tensor) – The rank of input tensor can be 2, 3, 4, 5. The data type is float32 or float64.

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

  • param_attr (ParamAttr|None|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 param_attr, the name of scale can be set in ParamAttr. If the Initializer of the param_attr is not set, the parameter is initialized with Xavier. If the param_attr is set to False, instance_norm will not create param_attr. Default: None.

  • bias_attr (ParamAttr|None|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 the bias_attr is set to False, instance_norm will not create bias_attr. Default: None.

  • name (string, Default None) – A name for this layer(optional). If set None, the layer will be named automatically.

Returns

A Tensor which is the result after applying instance normalization on the input, has same shape and data type with input.

Examples

import paddle
paddle.enable_static()
x = paddle.static.data(name='x', shape=[3, 7, 3, 7], dtype='float32')
hidden1 = paddle.static.nn.fc(x, size=200)
hidden2 = paddle.static.nn.instance_norm(hidden1)