温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

pytorch中torch.nn.AdaptiveAvgPool2d()自适应平均池化函数怎么用

发布时间:2021-08-18 15:21:04 来源:亿速云 阅读:338 作者:小新 栏目:开发技术

小编给大家分享一下pytorch中torch.nn.AdaptiveAvgPool2d()自适应平均池化函数怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

具体如下:

AdaptiveAvgPool2d

CLASStorch.nn.AdaptiveAvgPool2d(output_size)[SOURCE]

Applies a 2D adaptive average pooling over an input signal composed of several input planes.

The output is of size H x W, for any input size. The number of output features is equal to the number of input planes.

Parameters

output_size – the target output size of the image of the form H x W. Can be a tuple (H, W) or a single H for a square image H x H. H and W can be either a int, or None which means the size will be the same as that of the input.

Examples

>>> # target output size of 5x7
>>> m = nn.AdaptiveAvgPool2d((5,7))
>>> input = torch.randn(1, 64, 8, 9)
>>> output = m(input)
>>> # target output size of 7x7 (square)
>>> m = nn.AdaptiveAvgPool2d(7)
>>> input = torch.randn(1, 64, 10, 9)
>>> output = m(input)
>>> # target output size of 10x7
>>> m = nn.AdaptiveMaxPool2d((None, 7))
>>> input = torch.randn(1, 64, 10, 9)
>>> output = m(input)
>>> input = torch.randn(1, 3, 3, 3)
>>> input
tensor([[[[ 0.6574, 1.5219, -1.3590],
   [-0.1561, 2.7337, -1.8701],
   [-0.8572, 1.0238, -1.9784]],
 
   [[ 0.4284, 1.4862, 0.3352],
   [-0.7796, -0.8020, -0.1243],
   [-1.2461, -1.7069, 0.1517]],
 
   [[ 1.4593, -0.1287, 0.5369],
   [ 0.6562, 0.0616, 0.2611],
   [-1.0301, 0.4097, -1.9269]]]])
>>> m = nn.AdaptiveAvgPool2d((2, 2))
>>> output = m(input)
>>> output
tensor([[[[ 1.1892, 0.2566],
   [ 0.6860, -0.0227]],
 
   [[ 0.0833, 0.2238],
   [-1.1337, -0.6204]],
 
   [[ 0.5121, 0.1827],
   [ 0.0243, -0.2986]]]])
>>> 0.6574+1.5219+2.7337-0.1561
4.7569
>>> 4.7569/4
1.189225
>>>

看完了这篇文章,相信你对“pytorch中torch.nn.AdaptiveAvgPool2d()自适应平均池化函数怎么用”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI