最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pytorch中的卷積和池化計(jì)算方式詳解

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

TensorFlow里面的padding只有兩個(gè)選項(xiàng)也就是valid和same

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

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

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

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. 默認(rèn)值是kernel_size
  padding – implicit zero padding to be added on both side,默認(rèn)值是0
  dilation – a parameter that controls the stride of elements in the window,默認(rèn)值是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,向上取整和向下取整,默認(rèn)是向下取整
"""

不一樣的地方在于:第一點(diǎn),步長stride默認(rèn)值,上面默認(rèn)和設(shè)定的kernel_size一樣,下面默認(rèn)是1;第二點(diǎn),輸出通道的不一樣,上面的輸出通道和輸入通道是一樣的也就是沒有改變特征圖的數(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,默認(rèn)是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
"""

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

"""
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的計(jì)算公式,在(h,w)位置處的輸出值的計(jì)算。

pytorch中的F.avg_pool1d()平均池化操作作用于一維,input 的維度是三維比如[2,2,7]。F.avg_pool1d()中核size是3,步長是2表示每三個(gè)數(shù)取平均,每隔兩個(gè)數(shù)取一次.比如[1,3,3,4,5,6,7]安照3個(gè)數(shù)取均值,兩步取一次,那么結(jié)果就是[ 2.3333 ,4 ,6 ],也就是核是一維的,也只作用于一個(gè)維度。按照池化操作計(jì)算公式input size為[2,2,7],kernel size為3,步長為2,則輸出維度計(jì)算(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.那么核是二維的,所以取均值時(shí)也是覆蓋二維取的。輸出中第一個(gè)1.5的計(jì)算是:(1+2+1+2)/4=1.5.表示第一張圖像左上角的四個(gè)像素點(diǎn)的均值。按照池化操作計(jì)算公式input size為[2,2,4,4],kernel size為2*2,步長為2,則輸出維度計(jì)算(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中的卷積和池化計(jì)算方式詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解在Python中以絕對路徑或者相對路徑導(dǎo)入文件的方法

    詳解在Python中以絕對路徑或者相對路徑導(dǎo)入文件的方法

    這篇文章主要介紹了詳解在Python中以絕對路徑或者相對路徑導(dǎo)入文件的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 使用python中的openpyxl操作excel詳解

    使用python中的openpyxl操作excel詳解

    這篇文章主要介紹了使用python中的openpyxl操作excel詳解,openpyxl 模塊是一個(gè)讀寫Excel文檔的Python庫,本文就來講解如何使用openpyxl操作excel,需要的朋友可以參考下
    2023-07-07
  • python實(shí)現(xiàn)簡易版計(jì)算器

    python實(shí)現(xiàn)簡易版計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡易版計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • python中Pyqt5使用Qlabel標(biāo)簽進(jìn)行視頻播放

    python中Pyqt5使用Qlabel標(biāo)簽進(jìn)行視頻播放

    這篇文章主要介紹了python中Pyqt5使用Qlabel實(shí)現(xiàn)標(biāo)簽進(jìn)行視頻播放,QLabel是界面中的標(biāo)簽類,繼承自QFrame類,提供文本和圖像的顯示,是一種展示控件,下文相關(guān)內(nèi)容介紹需要的小伙伴可以參考一下
    2022-04-04
  • 用python爬取歷史天氣數(shù)據(jù)的方法示例

    用python爬取歷史天氣數(shù)據(jù)的方法示例

    這篇文章主要介紹了用python爬取歷史天氣數(shù)據(jù)的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Python使用matplotlib實(shí)現(xiàn)的圖像讀取、切割裁剪功能示例

    Python使用matplotlib實(shí)現(xiàn)的圖像讀取、切割裁剪功能示例

    這篇文章主要介紹了Python使用matplotlib實(shí)現(xiàn)的圖像讀取、切割裁剪功能,結(jié)合實(shí)例形式分析了Python基于matplotlib操作圖片的加載、讀取、坐標(biāo)控制及裁剪相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • Python學(xué)習(xí)筆記之解析json的方法分析

    Python學(xué)習(xí)筆記之解析json的方法分析

    這篇文章主要介紹了Python解析json的方法,結(jié)合實(shí)例形式分析了常見的Python解析與轉(zhuǎn)換json格式數(shù)據(jù)相關(guān)操作技巧,需要的朋友可以參考下
    2017-04-04
  • Python Requests庫及用法詳解

    Python Requests庫及用法詳解

    Requests庫作為Python中最受歡迎的HTTP庫之一,為開發(fā)人員提供了簡單而強(qiáng)大的方式來發(fā)送HTTP請求和處理響應(yīng),本文將帶領(lǐng)您深入探索Python Requests庫的世界,我們將從基礎(chǔ)知識(shí)開始,逐步深入,覆蓋各種高級用法和技巧,感興趣的朋友一起看看吧
    2024-06-06
  • Python數(shù)據(jù)分析之繪制m1-m2數(shù)據(jù)

    Python數(shù)據(jù)分析之繪制m1-m2數(shù)據(jù)

    這篇文章主要介紹了Python數(shù)據(jù)分析之繪制m1-m2數(shù)據(jù),文章基于python的相關(guān)資料展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • Django實(shí)現(xiàn)從數(shù)據(jù)庫中獲取到的數(shù)據(jù)轉(zhuǎn)換為dict

    Django實(shí)現(xiàn)從數(shù)據(jù)庫中獲取到的數(shù)據(jù)轉(zhuǎn)換為dict

    這篇文章主要介紹了Django實(shí)現(xiàn)從數(shù)據(jù)庫中獲取到的數(shù)據(jù)轉(zhuǎn)換為dict,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03

最新評論

沧州市| 余庆县| 固安县| 二手房| 望江县| 江永县| 安图县| 白山市| 嘉义市| 富蕴县| 措勤县| 闽侯县| 皋兰县| 苏州市| 申扎县| 北宁市| 甘洛县| 沧州市| 博乐市| 瓦房店市| 双牌县| 德保县| 黔西县| 奉贤区| 荆门市| 石台县| 三门县| 潍坊市| 日照市| 胶南市| 黄石市| 沂水县| 巨鹿县| 客服| 延寿县| 广饶县| 呼伦贝尔市| 田林县| 彩票| 宝清县| 色达县|