pytorch torch.nn.AdaptiveAvgPool2d()自適應(yīng)平均池化函數(shù)詳解
如題:只需要給定輸出特征圖的大小就好,其中通道數(shù)前后不發(fā)生變化。具體如下:
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()自適應(yīng)平均池化函數(shù)詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
PyQt5中QPushButton的用法詳細(xì)解析與應(yīng)用實戰(zhàn)
PyQt5 是一個用于創(chuàng)建圖形用戶界面的 Python 綁定庫,它基于 Qt5 應(yīng)用程序框架,在 PyQt5 中,QPushButton 是一個常用的控件,用于創(chuàng)建按鈕,允許用戶通過點擊來觸發(fā)某些操作,本文將詳細(xì)介紹 QPushButton 的用法,并通過實際案例來展示其強(qiáng)大的功能2024-07-07
django創(chuàng)建簡單的頁面響應(yīng)實例教程
這篇文章主要給大家介紹了關(guān)于django如何創(chuàng)建簡單的頁面響應(yīng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用django具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09

