nn.GroupNorm()

2022-09-02 13:07:43 浏览数 (1)

函数作用

各位看官老爷,如果觉得对您有用麻烦赏个子,创作不易,0.1元就行了。下面是微信乞讨码:

代码语言:javascript复制
>>> input2=torch.randn(1,4,2,2,3)           #输入维度为5维(b,c,l,h,w)
>>> nnnn=nn.GroupNorm(2,4)          #定义组规范化
>>> output1=nnnn(input2)
>>> output1
tensor([[[[[-0.7846,  0.0791,  1.5367],
           [ 0.3729, -0.6258, -0.4306]],
          [[-0.0724,  0.9401, -0.3869],
           [-1.1452,  1.1260,  2.3547]]],
         [[[ 1.3363,  1.1639, -1.5671],
           [-0.1317,  0.1545, -0.5496]],
          [[-1.8654,  0.1424, -0.3734],
           [ 0.2217, -0.3059, -1.1897]]],
         [[[-0.9365, -0.8634,  2.1091],
           [-0.2412, -2.1942,  1.1618]],
          [[-0.0543,  0.3332, -1.3826],
           [-0.6508,  0.7949, -0.6618]]],
         [[[ 1.4304,  0.8079, -0.6333],
           [ 0.9667, -0.7094,  0.2172]],
         [[-0.3731, -0.4647,  1.4705],
           [ 0.7568, -0.1945, -0.6886]]]]], grad_fn=<AddcmulBackward>)
>>> output1.size()                     #输出的size和输入相同
torch.Size([1, 4, 2, 2, 3])
>>>input2                         
tensor([[[[[-0.3088,  0.6669,  2.3133],
           [ 0.9987, -0.1293,  0.0911]],
          [[ 0.4958,  1.6394,  0.1405],
           [-0.7161,  1.8495,  3.2374]]],
         [[[ 2.0870,  1.8923, -1.1927],
           [ 0.4288,  0.7520, -0.0433]],
          [[-1.5297,  0.7383,  0.1557],
           [ 0.8279,  0.2320, -0.7664]]],
         [[[-1.1690, -1.0956,  1.8887],
           [-0.4709, -2.4317,  0.9377]],
          [[-0.2833,  0.1058, -1.6169],
           [-0.8822,  0.5693, -0.8932]]],
         [[[ 1.2074,  0.5824, -0.8645],
           [ 0.7418, -0.9409, -0.0107]],
          [[-0.6034, -0.6953,  1.2476],
           [ 0.5311, -0.4240, -0.9201]]]]])
>>> input2[0,0:2].mean()
tensor(0.5775)
>>> input2[0,0:2].var()
tensor(1.3314)
>>>nnn.weight
Parameter containing:
tensor([1., 1., 1., 1.], requires_grad=True)
>>> nnnn.bias
Parameter containing:
tensor([0., 0., 0., 0.], requires_grad=True)
>>> bb=nn.GroupNorm(2,4,affine=True)         #查看参数
>>> bb.weight
Parameter containing:
tensor([1., 1., 1., 1.], requires_grad=True)
>>> bb.bias
Parameter containing:
tensor([0., 0., 0., 0.], requires_grad=True)

0 人点赞