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

Pytorch之卷積層的使用詳解

 更新時(shí)間:2019年12月31日 10:31:39   作者:嘖嘖嘖biubiu  
今天小編就為大家分享一篇Pytorch之卷積層的使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

1.簡(jiǎn)介(torch.nn下的)

卷積層主要使用的有3類,用于處理不同維度的數(shù)據(jù)

參數(shù) Parameters:

in_channels(int) – 輸入信號(hào)的通道

out_channels(int) – 卷積產(chǎn)生的通道

kerner_size(int or tuple) - 卷積核的尺寸

stride(int or tuple, optional) - 卷積步長(zhǎng)

padding (int or tuple, optional)- 輸入的每一條邊補(bǔ)充0的層數(shù)

dilation(int or tuple, `optional``) – 卷積核元素之間的間距

groups(int, optional) – 從輸入通道到輸出通道的阻塞連接數(shù)

bias(bool, optional) - 如果bias=True,添加偏置

class torch.nn.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

一維卷積層。用于計(jì)算ECG等一維數(shù)據(jù)。

input: (N,C_in,L_in) N為批次,C_in即為in_channels,即一批內(nèi)輸入一維數(shù)據(jù)個(gè)數(shù),L_in是是一維數(shù)據(jù)基數(shù)

output: (N,C_out,L_out) N為批次,C_in即為out_channels,即一批內(nèi)輸出一維數(shù)據(jù)個(gè)數(shù),L_out是一維數(shù)據(jù)基數(shù)

class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

二維卷積層。用于計(jì)算CT斷層或MR斷層,或二維超聲圖像,自然圖像等二維數(shù)據(jù)。

self.conv1 = nn.Conv2d( # 1*28*28 -> 32*28*28
      in_channels=1,
      out_channels=32,
      kernel_size=5,
      stride=1,
      padding=2 #padding是需要計(jì)算的,padding=(stride-1)/2
    )

input: (N,C_in,H_in,W_in) N為批次,C_in即為in_channels,即一批內(nèi)輸入二維數(shù)據(jù)個(gè)數(shù),H_in是二維數(shù)據(jù)行數(shù),W_in是二維數(shù)據(jù)的列數(shù)

output: (N,C_out,H_out,W_out) N為批次,C_out即為out_channels,即一批內(nèi)輸出二維數(shù)據(jù)個(gè)數(shù),H_out是二維數(shù)據(jù)行數(shù),W_out是二維數(shù)據(jù)的列數(shù)

con2 = nn.Conv2d(1,16,5,1,2)
# con2(np.empty([1,1,28,28])) 只能接受tensor/variable
con2(torch.Tensor(1,1,28,28))
con2(Variable(torch.Tensor(1,1,28,28)))

class torch.nn.Conv3d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

三維卷積層。用于計(jì)算CT或MR等容積數(shù)據(jù),視頻數(shù)據(jù)等三維數(shù)據(jù)。

input: (N,C_in,D_in,H_in,W_in)

output: (N,C_out,D_out,H_out,W_out)

2.簡(jiǎn)介(torch.nn.functional下的)

在torch.nn.functional下也有卷積層,但是和torch.nn下的卷積層的區(qū)別在于,functional下的是函數(shù),不是實(shí)際的卷積層,而是有卷積層功能的卷積層函數(shù),所以它并不會(huì)出現(xiàn)在網(wǎng)絡(luò)的圖結(jié)構(gòu)中。

torch.nn.functional.conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1)

參數(shù):

- input – 輸入張量的形狀 (minibatch x in_channels x iW)

- weight – 過(guò)濾器的形狀 (out_channels, in_channels, kW)

- bias – 可選偏置的形狀 (out_channels)

- stride – 卷積核的步長(zhǎng),默認(rèn)為1

>>> filters = autograd.Variable(torch.randn(33, 16, 3))
>>> inputs = autograd.Variable(torch.randn(20, 16, 50))
>>> F.conv1d(inputs, filters)

torch.nn.functional.conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1)

>>> # With square kernels and equal stride
>>> filters = autograd.Variable(torch.randn(8,4,3,3))
>>> inputs = autograd.Variable(torch.randn(1,4,5,5))
>>> F.conv2d(inputs, filters, padding=1)

torch.nn.functional.conv3d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1)

>>> filters = autograd.Variable(torch.randn(33, 16, 3, 3, 3))
>>> inputs = autograd.Variable(torch.randn(20, 16, 50, 10, 20))
>>> F.conv3d(inputs, filters)

以上這篇Pytorch之卷積層的使用詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

  • 深入了解Python中Pytest Markers的使用方法

    深入了解Python中Pytest Markers的使用方法

    從這篇開始,逐一解決fixture是啥,mark是啥,參數(shù)request是啥,鉤子函數(shù)是啥,parametrize參數(shù)化是啥,這些問(wèn)題,本片先介紹一下mark是啥,以及如何使用
    2023-09-09
  • Python中str字符串的內(nèi)置方法詳解

    Python中str字符串的內(nèi)置方法詳解

    這篇文章主要介紹了Python中str字符串的內(nèi)置方法詳解,在?python?中字符串有許多內(nèi)置的方法,在日常編程中會(huì)經(jīng)常使用到,熟練運(yùn)用了能夠在很多場(chǎng)景大大的提高我們的工作效率,需要的朋友可以參考下
    2023-08-08
  • 對(duì)Python正則匹配IP、Url、Mail的方法詳解

    對(duì)Python正則匹配IP、Url、Mail的方法詳解

    今天小編就為大家分享一篇對(duì)Python正則匹配IP、Url、Mail的方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • Python函數(shù)中的可變長(zhǎng)參數(shù)詳解

    Python函數(shù)中的可變長(zhǎng)參數(shù)詳解

    在本篇文章里小編給大家整理的是關(guān)于Python函數(shù)中的可變長(zhǎng)參數(shù)的相關(guān)知識(shí)點(diǎn)內(nèi)容,有需要的朋友們參考下。
    2019-09-09
  • 解決Python import docx出錯(cuò)DLL load failed的問(wèn)題

    解決Python import docx出錯(cuò)DLL load failed的問(wèn)題

    今天小編就為大家分享一篇解決Python import docx出錯(cuò)DLL load failed的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • PyCharm 2020.2.2 x64 下載并安裝的詳細(xì)教程

    PyCharm 2020.2.2 x64 下載并安裝的詳細(xì)教程

    這篇文章主要介紹了PyCharm 2020.2.2 x64 下載并安裝的詳細(xì)教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • 三個(gè)python爬蟲項(xiàng)目實(shí)例代碼

    三個(gè)python爬蟲項(xiàng)目實(shí)例代碼

    這篇文章主要介紹了三個(gè)python爬蟲項(xiàng)目實(shí)例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • unittest+coverage單元測(cè)試代碼覆蓋操作實(shí)例詳解

    unittest+coverage單元測(cè)試代碼覆蓋操作實(shí)例詳解

    這篇文章主要為大家詳細(xì)介紹了unittest+coverage單元測(cè)試代碼覆蓋操作的實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Python的組合模式與責(zé)任鏈模式編程示例

    Python的組合模式與責(zé)任鏈模式編程示例

    這篇文章主要介紹了Python的組合模式與責(zé)任鏈模式編程示例,組合模式與責(zé)任鏈模式都屬于Python的設(shè)計(jì)模式,需要的朋友可以參考下
    2016-02-02
  • 最新評(píng)論