欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pytorch中的卷積和池化計算方式詳解

 更新時間:2020年01月03日 10:06:37   作者:一只tobey  
今天小編就為大家分享一篇pytorch中的卷積和池化計算方式詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

TensorFlow里面的padding只有兩個選項也就是valid和same

pytorch里面的padding么有這兩個選項,它是數(shù)字0,1,2,3等等,默認是0

所以輸出的h和w的計算方式也是稍微有一點點不同的:tf中的輸出大小是和原來的大小成倍數(shù)關(guān)系,不能任意的輸出大?。欢鴑n輸出大小可以通過padding進行改變

nn里面的卷積操作或者是池化操作的H和W部分都是一樣的計算公式:H和W的計算

class torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False):
"""
Parameters: 
  kernel_size – the size of the window to take a max over
  stride – the stride of the window. 默認值是kernel_size
  padding – implicit zero padding to be added on both side,默認值是0
  dilation – a parameter that controls the stride of elements in the window,默認值是1
  return_indices – if True, will return the max indices along with the outputs. Useful when Unpooling later
  ceil_mode – when True, will use ceil instead of floor to compute the output shape,向上取整和向下取整,默認是向下取整
"""

不一樣的地方在于:第一點,步長stride默認值,上面默認和設(shè)定的kernel_size一樣,下面默認是1;第二點,輸出通道的不一樣,上面的輸出通道和輸入通道是一樣的也就是沒有改變特征圖的數(shù)目,下面改變特征圖的數(shù)目為out_channels

class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True):
    pass
"""
Parameters: 
  in_channels (int) – Number of channels in the input image
  out_channels (int) – Number of channels produced by the convolution
  kernel_size (int or tuple) – Size of the convolving kernel
  stride (int or tuple, optional) – Stride of the convolution. Default: 1,默認是1
  padding (int or tuple, optional) – Zero-padding added to both sides of the input. Default: 0
  dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1
  groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1
  bias (bool, optional) – If True, adds a learnable bias to the output. Default: True
"""

第三點不一樣是卷積有一個參數(shù)groups,將特征圖分開給不同的卷積進行操作然后再整合到一起,xception就是利用這一個。

"""
At groups=1, all inputs are convolved to all outputs.
At groups=2, the operation becomes equivalent to having two conv layers side by side, each seeing half the input channels, and producing half the output channels, and both subsequently concatenated.
At groups= in_channels, each input channel is convolved with its own set of filters (of size ⌊out_channelsin_channels⌋
).
"""

pytorch AvgPool2d函數(shù)

class torch.nn.AvgPool2d(kernel_size, stride=None, padding=0, 
             ceil_mode=False, count_include_pad=True):
  pass
"""
kernel_size: the size of the window
stride: the stride of the window. Default value is :attr:`kernel_size`
padding: implicit zero padding to be added on both sides
ceil_mode: when True, will use `ceil` instead of `floor` to compute the output shape
count_include_pad: when True, will include the zero-padding in the averaging calculation
"""

shape的計算公式,在(h,w)位置處的輸出值的計算。

pytorch中的F.avg_pool1d()平均池化操作作用于一維,input 的維度是三維比如[2,2,7]。F.avg_pool1d()中核size是3,步長是2表示每三個數(shù)取平均,每隔兩個數(shù)取一次.比如[1,3,3,4,5,6,7]安照3個數(shù)取均值,兩步取一次,那么結(jié)果就是[ 2.3333 ,4 ,6 ],也就是核是一維的,也只作用于一個維度。按照池化操作計算公式input size為[2,2,7],kernel size為3,步長為2,則輸出維度計算(7-3)/2+1=3所以輸出維度是[2,2,3],這與輸出結(jié)果是一致的。

pytorch中的F.avg_pool2d(),input 是維度是4維如[2,2,4,4],表示這里批量數(shù)是2也就是兩張圖像,這里通道數(shù)量是2,圖像是size 是4*4的.核size是(2,2),步長是(2,2)表示被核覆蓋的數(shù)取平均,橫向縱向的步長都是2.那么核是二維的,所以取均值時也是覆蓋二維取的。輸出中第一個1.5的計算是:(1+2+1+2)/4=1.5.表示第一張圖像左上角的四個像素點的均值。按照池化操作計算公式input size為[2,2,4,4],kernel size為2*2,步長為2,則輸出維度計算(4-2)/2+1=2所以輸出維度是[2,2,2,2],這與輸出結(jié)果是一致的。

Conv3d函數(shù)

class torch.nn.Conv3d(in_channels, out_channels, kernel_size, stride=1,
           padding=0, dilation=1, groups=1, bias=True):
  pass
"""
in_channels (int): Number of channels in the input image
out_channels (int): Number of channels produced by the convolution
kernel_size (int or tuple): Size of the convolving kernel
stride (int or tuple, optional): Stride of the convolution. Default: 1
padding (int or tuple, optional): Zero-padding added to all three sides of the input. Default: 0
dilation (int or tuple, optional): Spacing between kernel elements. Default: 1
groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1
bias (bool, optional): If ``True``, adds a learnable bias to the output. Default: ``True``
Shape:
    - Input: :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`
    - Output: :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`
"""
  C_out = out_channels

以上這篇pytorch中的卷積和池化計算方式詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • OpenCV制作Mask圖像掩碼的案例

    OpenCV制作Mask圖像掩碼的案例

    這篇文章主要介紹了OpenCV制作Mask圖像掩碼的案例,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-02-02
  • 一篇文章從零開始創(chuàng)建conda環(huán)境、常用命令的使用及pycharm配置項目環(huán)境

    一篇文章從零開始創(chuàng)建conda環(huán)境、常用命令的使用及pycharm配置項目環(huán)境

    在Conda中創(chuàng)建新環(huán)境是一個非常有用的做法,尤其是當你需要為不同的項目安裝不同版本的軟件包時,這篇文章主要給大家介紹了關(guān)于從零開始創(chuàng)建conda環(huán)境、常用命令的使用及pycharm配置項目環(huán)境的相關(guān)資料,需要的朋友可以參考下
    2024-07-07
  • django商品分類及商品數(shù)據(jù)建模實例詳解

    django商品分類及商品數(shù)據(jù)建模實例詳解

    這篇文章主要介紹了django商品分類及商品數(shù)據(jù)建模實例代碼內(nèi)容,需要的朋友們學(xué)習(xí)參考下。
    2020-01-01
  • python計算n的階乘的方法代碼

    python計算n的階乘的方法代碼

    在本篇文章里小編給各位整理的是關(guān)于python計算n的階乘的相關(guān)知識點,需要的朋友們參考下。
    2019-10-10
  • Python中使用matplotlib繪制各類圖表示例詳解

    Python中使用matplotlib繪制各類圖表示例詳解

    這篇文章主要給大家介紹了關(guān)于Python中使用matplotlib繪制各類圖表的相關(guān)資料,matplotlib是python的一個庫,內(nèi)部儲存了大量的函數(shù)用于繪制圖像,通常會與pandas和numpy庫一起使用,平常我們通常只是用里面的pyplot模塊,需要的朋友可以參考下
    2023-10-10
  • 利用Python爬蟲實現(xiàn)搶購某寶秒殺商品

    利用Python爬蟲實現(xiàn)搶購某寶秒殺商品

    這篇文章主要介紹了利用Python爬蟲實現(xiàn)搶購某寶秒殺商品,文章基于python的相關(guān)資料展開詳細的內(nèi)容介紹具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • Pygame如何使用精靈和碰撞檢測

    Pygame如何使用精靈和碰撞檢測

    本文主要介紹了Pygame如何使用精靈和碰撞檢測,它們能夠幫助我們跟蹤屏幕上移動的大量圖像。我們還會了解如何檢測兩個圖像相互重疊或者碰撞的方法。
    2021-11-11
  • python中的Numpy二維數(shù)組遍歷與二維數(shù)組切片后遍歷效率比較

    python中的Numpy二維數(shù)組遍歷與二維數(shù)組切片后遍歷效率比較

    這篇文章主要介紹了python中的Numpy二維數(shù)組遍歷與二維數(shù)組切片后遍歷效率比較,在python-numpy使用中,可以用雙層?for循環(huán)對數(shù)組元素進行訪問,也可以切片成每一行后進行一維數(shù)組的遍歷,下面小編擊來舉例介紹吧,需要的朋友可以參考一下
    2022-03-03
  • python繪制散點圖和折線圖的方法

    python繪制散點圖和折線圖的方法

    這篇文章主要為大家詳細介紹了python繪制散點圖和折線圖的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 利用OpenCV給彩色圖像添加椒鹽噪聲的方法

    利用OpenCV給彩色圖像添加椒鹽噪聲的方法

    椒鹽噪聲是數(shù)字圖像中的常見噪聲,一般是圖像傳感器、傳輸信道及解碼處理等產(chǎn)生的黑白相間的亮暗點噪聲,椒鹽噪聲常由圖像切割產(chǎn)生,這篇文章主要給大家介紹了關(guān)于利用OpenCV給彩色圖像添加椒鹽噪聲的相關(guān)資料,需要的朋友可以參考下
    2021-10-10

最新評論