batch_norm( x, running_mean, running_var, weight, bias, training=False, momentum=0.9, epsilon=1e-05, data_format='NCHW', use_global_stats=None, name=None )
Applies Batch Normalization as described in the paper Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift .
nn.functional.batch_norm is uesd for nn.BatchNorm1D, nn.BatchNorm2D, nn.BatchNorm3D. Please use above API for BatchNorm.
x (Tesnor) – input value. It’s data type should be float32, float64.
running_mean (Tensor) – running mean.
running_var (Tensor) – running variance.
weight (Tensor) – The weight tensor of batch_norm, can not be None.
bias (Tensor) – The bias tensor of batch_norm can not be None.
epsilon (float, optional) – The small value added to the variance to prevent division by zero. Default: 1e-5.
momentum (float, optional) – The value used for the moving_mean and moving_var computation. Default: 0.9.
training (bool, optional) – True means train mode which compute by batch data and track global mean and var during train period. False means inference mode which compute by global mean and var which calculated by train period. Defalut False.
data_format (str, optional) – Specify the input data format, may be “NC”, “NCL”, “NCHW”, “NCDHW”, “NLC”, “NHWC” or “NDHWC”. Defalut “NCHW”.
use_global_stats (bool|None, optional) – Whether to use global mean and variance. If set to False, use the statistics of one mini-batch, if set to True, use the global statistics, if set to None, use global statistics in the test phase and use the statistics of one mini-batch in the training phase. Default: None.
name (str, optional) – Name for the BatchNorm, default is None. For more information, please refer to Name..
import paddle import numpy as np x = np.random.seed(123) x = np.random.random(size=(2, 1, 2, 3)).astype('float32') running_mean = np.random.random(size=1).astype('float32') running_variance = np.random.random(size=1).astype('float32') weight_data = np.random.random(size=1).astype('float32') bias_data = np.random.random(size=1).astype('float32') x = paddle.to_tensor(x) rm = paddle.to_tensor(running_mean) rv = paddle.to_tensor(running_variance) w = paddle.to_tensor(weight_data) b = paddle.to_tensor(bias_data) batch_norm_out = paddle.nn.functional.batch_norm(x, rm, rv, w, b) print(batch_norm_out)