torch.nn.AdaptiveAvgPool1d(N)函数解读

  • 函数作用
    AdaptiveAvgPool1d(N) 对于一个输入BCL的tensor进行一维的pool,变为BCN
  • 代码示例
>>> import torch
>>> import torch.nn as nn
>>> a=torch.ones(2,3,4)
>>> a[0,1,2]=0
>>> a
tensor([[[1., 1., 1., 1.],
         [1., 1., 0., 1.],
         [1., 1., 1., 1.]],
         [[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]]])
>>> nn.AdaptiveAvgPool1d(5)(a)
tensor([[[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
         [1.0000, 1.0000, 0.5000, 0.5000, 1.0000],
         [1.0000, 1.0000, 1.0000, 1.0000, 1.0000]],
         [[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
         [1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
         [1.0000, 1.0000, 1.0000, 1.0000, 1.0000]]])
>>> nn.AdaptiveAvgPool1d(5)(a).shape
torch.Size([2, 3, 5])
>>> nn.AdaptiveAvgPool1d(2)(a)
tensor([[[1.0000, 1.0000],
         [1.0000, 0.5000],
         [1.0000, 1.0000]],
         [[1.0000, 1.0000],
         [1.0000, 1.0000],
         [1.0000, 1.0000]]])
>>> nn.AdaptiveAvgPool1d(2)(a).shape
torch.Size([2, 3, 2])

你可能感兴趣的:(torch.nn.AdaptiveAvgPool1d(N)函数解读)