AdaptiveAvgPool1d(N)
对一个C*H*W的三维输入Tensor, 池化输出为C*H*N, 即按照H轴逐行对W轴平均池化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
>>> 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( 1 )(a)
tensor([[[ 1.0000 ],
[ 0.7500 ],
[ 1.0000 ]],
[[ 1.0000 ],
[ 1.0000 ],
[ 1.0000 ]]])
|
AdaptiveAvgPool2d((M,N))
对一个B*C*H*W的四维输入Tensor, 池化输出为B*C*M*N, 即按照C轴逐通道对H*W平面平均池化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
>>> a = torch.ones( 2 , 2 , 3 , 4 )
>>> a[:,:,:, 1 ] = 0
>>> a
tensor([[[[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ]],
[[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ]]],
[[[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ]],
[[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ],
[ 1. , 0. , 1. , 1. ]]]])
>>> nn.AdaptiveAvgPool2d(( 1 , 2 ))(a)
tensor([[[[ 0.5000 , 1.0000 ]],
[[ 0.5000 , 1.0000 ]]],
[[[ 0.5000 , 1.0000 ]],
[[ 0.5000 , 1.0000 ]]]])
>>> nn.AdaptiveAvgPool2d( 1 )(a)
tensor([[[[ 0.7500 ]],
[[ 0.7500 ]]],
[[[ 0.7500 ]],
[[ 0.7500 ]]]])
|
AdaptiveAvgPool3d((M,N,K))
对一个B*C*D*H*W的五维输入Tensor, 池化输出为B*C*M*N*K, 即按照C轴逐通道对D*H*W平面平均池化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
>>> a = torch.ones( 1 , 2 , 2 , 3 , 4 )
>>> a[ 0 , 0 ,:,:, 0 : 2 ] = 0
>>> a
tensor([[[[[ 0. , 0. , 1. , 1. ],
[ 0. , 0. , 1. , 1. ],
[ 0. , 0. , 1. , 1. ]],
[[ 0. , 0. , 1. , 1. ],
[ 0. , 0. , 1. , 1. ],
[ 0. , 0. , 1. , 1. ]]],
[[[ 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. ]],
[[ 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. ],
[ 1. , 1. , 1. , 1. ]]]]])
>>> nn.AdaptiveAvgPool3d(( 1 , 1 , 2 ))(a)
tensor([[[[[ 0. , 1. ]]],
[[[ 1. , 1. ]]]]])
>>> nn.AdaptiveAvgPool3d( 1 )(a)
tensor([[[[[ 0.5000 ]]],
[[[ 1.0000 ]]]]])
|
以上这篇对Pytorch中Tensor的各种池化操作解析就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/TianxiaoV/article/details/85158803