https://blog.csdn.net/qq_40210472/article/details/87895626
1. nn.Conv2d
nn.Conv2d
輸入信號的形式為(N, Cin, H, W), N表示batch size,Cin表示channel個數,H,W分別表示特征圖的高和寬。
參數說明:
-
stride(步長):控制cross-correlation的步長,可以設為1個int型數或者一個(int, int)型的tuple。
-
padding(補0):控制zero-padding的數目。
-
dilation(擴張):控制kernel點(卷積核點)的間距;
-
groups(卷積核個數):這個比較好理解,通常來說,卷積個數唯一,但是對某些情況,可以設置范圍在1 —— in_channels中數目的卷積核:
class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)
-
參數kernel_size,stride, padding,dilation也可以是一個int的數據
-
此時卷積height 和 width值相同; 也可以是一個tuple數組,tuple的第一維度表示height的數值,tuple的第二維度表示width的數值。
- 經常使用二維的kernel_size,如(3,5),是tuple數組。
參數
-
in_channels(int) – 輸入信號的通道
-
out_channels(int) – 卷積產生的通道
-
kerner_size(int or tuple) - 卷積核的尺寸,在nlp中tuple用更多,(n,embed_size)
-
stride(int or tuple, optional) - 卷積步長
-
padding(int or tuple, optional) - 輸入的每一條邊補充0的層數
-
dilation(int or tuple, optional) – 卷積核元素之間的間距
-
groups(int, optional) – 從輸入通道到輸出通道的阻塞連接數
-
bias(bool, optional) - 如果bias=True,添加偏置
2. nn.MaxPool2d
class torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)
- 如果padding 不是0,會在輸入的每一邊添加相應數目0,如padding=1,則在每一邊分別補0,其實最后的結果補出來是bias
參數:
-
kernel_size(int or tuple): max pooling的窗口大小,可以為tuple,在nlp中tuple用更多,(n, 1)
- (n, m): height/n, width/m
-
stride(int or tuple, optional): max pooling的窗口移動的步長。默認值是kernel_size
-
padding(int or tuple, optional): 輸入的每一條邊補充0的層數
-
dilation(int or tuple, optional): 一個控制窗口中元素步幅的參數
-
return_indices: 如果等於True,會返回輸出最大值的序號,對於上采樣操作會有幫助
-
ceil_mode: 如果等於True,計算輸出信號大小的時候,會使用向上取整,代替默認的向下取整的操作