import torch x = torch.randn(2,1,7,3) conv = torch.nn.Conv2d(1,8,(2,3)) res = conv(x) print(res.shape) # shape = (2, 8, 6, 1)
輸入x:
[ batch_size, channels, height_1, width_1 ]
batch_size | 一個batch中樣例的個數 | 2 |
channels | 通道數,也就是當前層的深度 | 1 |
height_1 | 圖片的高 | 7 |
width_1 | 圖片的寬 | 3 |
Conv2d的參數
[ channels, output, height_2, width_2 ]
channels | 通道數,和上面保持一致,也就是當前層的深度 | 1 |
output | 輸出的深度 | 8 |
height_2 | 過濾器filter的高 | 2 |
weight_2 | 過濾器filter的寬 | 3 |
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)
in_channels |
Number of channels in the input image |
out_channels |
Number of channels produced by the convolution |
kernel_size |
卷積核尺寸 |
stride |
步長,控制cross-correlation的步長,可以設為1個int型數或者一個(int, int)型的tuple。 |
padding |
(補0):控制zero-padding的數目。 |
dilation |
(擴張):控制kernel點(卷積核點)的間距 |
groups |
(卷積核個數):通常來說,卷積個數唯一,但是對某些情況,可以設置范圍在1 —— in_channels中數目的卷積核: |
bias |
adds a learnable bias to the output. |
輸出res:
[ batch_size,output, height_3, width_3 ]
batch_size | 一個batch中樣例的個數,同上 | 2 |
output | 輸出的深度 | 8 |
height_3 | 卷積結果的高度 | h1-h2+1 = 7-2+1 = 6 |
weight_3 | 卷積結果的寬度 | w1-w2+1 = 3-3+1 = 1 |
參考
torch.nn.Conv2d
torch.nn.MaxPool2d
————————————————
版權聲明:本文為CSDN博主「huxuedan01」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/m0_37586991/article/details/87855342