InstanceNorm1D¶
- class paddle.nn. InstanceNorm1D ( num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format='NCL', name=None ) [source]
-
Create a callable object of InstanceNorm1D. Applies Instance Normalization over a 3D input (a mini-batch of 1D inputs with additional channel dimension) as described in the paper Instance Normalization: The Missing Ingredient for Fast Stylization .
DataLayout: NCL [batch, in_channels, length]
\(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, may be “NC”, “NCL”. Default “NCL”.
name (str, optional) – Name for the InstanceNorm, default is None. For more information, please refer to Name .
- Shape:
-
x: 2-D or 3-D tensor with shape: (batch, num_features) or (batch, num_features, length).
output: 3-D tensor with same shape as input x.
- Returns
-
None.
Examples
>>> import paddle >>> paddle.seed(100) >>> x = paddle.rand((2, 2, 3)) >>> instance_norm = paddle.nn.InstanceNorm1D(2) >>> instance_norm_out = instance_norm(x) >>> print(instance_norm_out) Tensor(shape=[2, 2, 3], dtype=float32, place=Place(cpu), stop_gradient=False, [[[ 1.32132232, -0.22444785, -1.09687424], [ 1.29506636, -0.15688568, -1.13818073]], [[-0.27764025, 1.33961368, -1.06197333], [ 0.44484580, -1.38489723, 0.94005162]]])