class torch.nn.BatchNorm1d(num_features, eps=1e-05, momentum=0.1, affine=True) [source]
对小批量(mini-batch)的2d或3d输入进行批标准化(Batch Normalization)操作
在每一个小批量(mini-batch)数据中,计算输入各个维度的均值和标准差。gamma与beta是可学习的大小为C的参数向量(C为输入大小)
在训练时,该层计算每次输入的均值与方差,并进行移动平均。移动平均默认的动量值为0.1。
在验证时,训练求得的均值/方差将用于标准化验证数据。
参数:
num_features: 来自期望输入的特征数,C from an expected input of size (N,C,L) or L from input of size (N,L)
eps: 为保证数值稳定性(分母不能趋近或取0),给分母加上的值。默认为1e-5。
momentum: 动态均值和动态方差所使用的动量。默认为0.1。
affine: 一个布尔值,当设为true,给该层添加可学习的仿射变换参数。
Shape: - 输入:(N, C)或者(N, C, L) - 输出:(N, C)或者(N,C,L)(输入输出相同)
例子
m = nn.BatchNorm1d(5, affine=False)
m1 = nn.BatchNorm1d(5, affine=True)
input = autograd.Variable(torch.randn(5, 5))
output = m(input)
output1 = m1(input)
print(input, '\n',output,'\n',output1)
tensor([[-0.6046, -0.8939, 1.3246, 0.2621, 1.0777],
[ 0.9088, -0.6219, 0.9589, 0.7307, 0.5221],
[ 1.7435, 0.6662, -0.5827, 0.3325, -0.8179],
[-0.2250, 0.9930, 0.0504, -0.4509, 1.6605],
[-0.5742, 1.6543, 0.6083, 0.5746, -0.3208]])
tensor([[-0.9212, -1.2920, 1.2648, -