pytorch中的torch.nn.Conv2d()函數(shù)圖文詳解
一、官方文檔介紹

nn.Conv2d:對由多個輸入平面組成的輸入信號進行二維卷積


二、torch.nn.Conv2d()函數(shù)詳解
參數(shù)詳解
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)
| 參數(shù) | 參數(shù)類型 | ||
|---|---|---|---|
| in_channels | int | Number of channels in the input image | 輸入圖像通道數(shù) |
| out_channels | int | Number of channels produced by the convolution | 卷積產(chǎn)生的通道數(shù) |
| kernel_size | (int or tuple) | Size of the convolving kernel | 卷積核尺寸,可以設為1個int型數(shù)或者一個(int, int)型的元組。例如(2,3)是高2寬3卷積核 |
| stride | (int or tuple, optional) | Stride of the convolution. Default: 1 | 卷積步長,默認為1??梢栽O為1個int型數(shù)或者一個(int, int)型的元組。 |
| padding | (int or tuple, optional) | Zero-padding added to both sides of the input. Default: 0 | 填充操作,控制padding_mode的數(shù)目。 |
| padding_mode | (string, optional) | ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’ | padding模式,默認為Zero-padding 。 |
| dilation | (int or tuple, optional) | Spacing between kernel elements. Default: 1 | 擴張操作:控制kernel點(卷積核點)的間距,默認值:1。 |
| groups | (int, optional) | Number of blocked connections from input channels to output channels. Default: 1 | group參數(shù)的作用是控制分組卷積,默認不分組,為1組。 |
| bias | (bool, optional) | If True, adds a learnable bias to the output. Default: True | 為真,則在輸出中添加一個可學習的偏差。默認:True。 |
參數(shù)dilation——擴張卷積(也叫空洞卷積)
dilation操作動圖演示如下:
Dilated Convolution with a 3 x 3 kernel and dilation rate 2
擴張卷積核為3×3,擴張率為2

參數(shù)groups——分組卷積
Group Convolution顧名思義,則是對輸入feature map進行分組,然后每組分別卷積。


三、代碼實例
import torch x = torch.randn(3,1,5,4) print(x) conv = torch.nn.Conv2d(1,4,(2,3)) res = conv(x) print(res.shape) # torch.Size([3, 4, 4, 2])
輸入:x[ batch_size, channels, height_1, width_1 ]
- batch_size,一個batch中樣本的個數(shù) 3
- channels,通道數(shù),也就是當前層的深度 1
- height_1, 圖片的高 5
- width_1, 圖片的寬 4
卷積操作:Conv2d[ channels, output, height_2, width_2 ]
- channels,通道數(shù),和上面保持一致,也就是當前層的深度 1
- output ,輸出的深度 4【需要4個filter】
- height_2,卷積核的高 2
- width_2,卷積核的寬 3
輸出:res[ batch_size,output, height_3, width_3 ]
- batch_size,,一個batch中樣例的個數(shù),同上 3
- output, 輸出的深度 4
- height_3, 卷積結果的高度 4
- width_3,卷積結果的寬度 2
一個樣本卷積示例:


總結
到此這篇關于pytorch中torch.nn.Conv2d()函數(shù)的文章就介紹到這了,更多相關pytorch torch.nn.Conv2d()函數(shù)內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python實現(xiàn)自定義順序、排列寫入數(shù)據(jù)到Excel的方法
這篇文章主要介紹了Python實現(xiàn)自定義順序、排列寫入數(shù)據(jù)到Excel的方法,涉及Python針對Excel文件的數(shù)據(jù)處理及讀寫相關操作技巧,需要的朋友可以參考下2018-04-04
舉例講解Python的lambda語句聲明匿名函數(shù)的用法
匿名函數(shù)現(xiàn)在已經(jīng)成了各大編程語言爭相標配的熱門特性,無需用函數(shù)名來定義函數(shù)的方式在很多場合下書寫起來十分炫酷,這里我們就來舉例講解Python的lambda語句聲明匿名函數(shù)的用法2016-07-07
python pyecharts 實現(xiàn)一個文件繪制多張圖
這篇文章主要介紹了python pyecharts 實現(xiàn)一個文件繪制多張圖,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05
TensorFlow實現(xiàn)模型斷點訓練,checkpoint模型載入方式
這篇文章主要介紹了TensorFlow實現(xiàn)模型斷點訓練,checkpoint模型載入方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05

