BatchNorm和Dropout的使用

import torch
m = torch.nn.BatchNorm1d(10)
m = torch.nn.BatchNorm1d(10,affine=False)
input = torch.autograd.Variable(torch.randn(20,10))
output = m(input)
print(input,'\n',output)
tensor([[-0.5140,  1.7968, -0.1464, -0.1136, -2.2092,  0.0041,  2.2642,  0.6227,
         -2.1999, -1.6235],
        [-0.5835, -0.2935,  0.5938, -1.7395, -0.4505, -1.2027,  2.0447, -0.8712,
          1.2031,  0.1172],
         -0.8245, -0.3582],
        [-1.0625, -0.9335, -0.3063, -0.6901, -0.8580,  0.8256, -0.1621, -0.1163,
         -0.5484,  0.3952]]) 
 tensor([[-9.2817e-02,  1.3946e+00, -2.9467e-01, -2.3935e-01, -1.8327e+00,
          4.4508e-03,  2.0820e+00,  9.7547e-01, -1.7035e+00, -1.4572e+00],
         -9.2472e-01, -4.4264e-02, -7.2612e-01, -1.2803e-01, -1.8633e+00],
        [-6.2177e-01, -8.6190e-01, -4.3757e-01, -7.9025e-01, -6.0058e-01,
          9.1740e-01, -3.3592e-01,  1.7679e-01,  9.0570e-02,  5.2757e-01]])
import torch
torch.manual_seed(1)
m = torch.nn.Dropout(p=0.5)
input = torch.autograd.Variable(torch.randn(5,5))
output = m(input)
print(input)
print(output)
tensor([[-1.5256, -0.7502, -0.6540, -1.6095, -0.1002],
        [-0.6092, -0.9798, -1.6091, -0.7121,  1.1712],
        [ 1.7674, -0.0954,  0.1394, -1.5785, -0.3206],
        [-0.2993,  1.8793,  0.3357,  0.2753,  1.7163],
        [-0.0561,  0.9107, -1.3924,  2.6891, -0.1110]])
tensor([[-3.0512, -0.0000, -0.0000, -0.0000, -0.0000],
        [-1.2184, -1.9595, -0.0000, -1.4243,  0.0000],
        [ 3.5349, -0.1907,  0.2787, -0.0000, -0.0000],
        [-0.5987,  3.7587,  0.6715,  0.5507,  3.4326],
        [-0.0000,  0.0000, -0.0000,  5.3782, -0.2220]])

猜你喜欢

转载自blog.csdn.net/qq_42830971/article/details/126558171