pytorch torch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解
如题:只需要给定输出特征图的大小就好,其中通道数前后不发生变化。具体如下:
AdaptiveAvgPool2d
CLASStorch.nn.AdaptiveAvgPool2d(output_size)[SOURCE]
Appliesa2Dadaptiveaveragepoolingoveraninputsignalcomposedofseveralinputplanes.
TheoutputisofsizeHxW,foranyinputsize.Thenumberofoutputfeaturesisequaltothenumberofinputplanes.
Parameters
output_size–thetargetoutputsizeoftheimageoftheformHxW.Canbeatuple(H,W)orasingleHforasquareimageHxH.HandWcanbeeitheraint,orNonewhichmeansthesizewillbethesameasthatoftheinput.
Examples
>>>#targetoutputsizeof5x7 >>>m=nn.AdaptiveAvgPool2d((5,7)) >>>input=torch.randn(1,64,8,9) >>>output=m(input) >>>#targetoutputsizeof7x7(square) >>>m=nn.AdaptiveAvgPool2d(7) >>>input=torch.randn(1,64,10,9) >>>output=m(input) >>>#targetoutputsizeof10x7 >>>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 >>>
以上这篇pytorchtorch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。