Conv2d()的参数及用法

二维卷积 

输入的大小:(N, C_{in}, H_{in}, W_{in}) or (C_{in}, H_{in}, W_{in})

输出的大小:(N, C_{\text{out}}, H_{\text{out}}, W_{\text{out}}) or (C_{out}, H_{out}, W_{out})

\text{out}(N_i, C_{\text{out}_j}) = \text{bias}(C_{\text{out}_j}) + \sum_{k = 0}^{C_{\text{in}} - 1} \text{weight}(C_{\text{out}_j}, k) \star \text{input}(N_i, k)

其中,星号表示有效的2D相互关联运算符;N为batch;C表示channel的数量;H W分别为输入的高度和宽度。 

H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[0] - \text{dilation}[0] \times (\text{kernel\_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor

W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[1] - \text{dilation}[1] \times (\text{kernel\_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor

--in_channels (int):输入图像中的通道数。例如,RGB3通道彩色图像,灰度为1.

--out_channels (int):卷积核产生的通道数。也就是卷积核的个数,每一个卷积核产生一个输出通道。

--kernel_size (int或tuple):卷积核的大小。单个数值时,即为方形,还可以(3,5),表示宽3高5.

--stride (int或tuple,可选,默认:1):卷积的步幅。

--padding (int, tuple或str,可选,默认:0):填充到'输入'的所有四个边(一圈)。

--padding_mode(str,可选, 默认值:'zeros'):``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``.

--dilation (int或tuple,可选,默认值:1):内核元素之间的间距,即卷积核的膨胀率。

--groups (int,可选,默认值:1):从输入通道到输出通道的阻塞连接数。

--bias (bool,可选,默认值:true):如果为“True”,则在输出中添加可学习的偏差。

属性:

weight (Tensor): 
    shape:
  The values of these weights are sampled from 
   其中, 
bias (Tensor): 
    shape:(out_channels). If :attr:`bias` is ``True``,
    then the values of these weights are sampled from 
    其中,

例子:

>>> # With square kernels and equal stride
>>> m = nn.Conv2d(16, 33, 3, stride=2)
>>> # non-square kernels and unequal stride and with padding
>>> m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
>>> # non-square kernels and unequal stride and with padding and dilation
>>> m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1))
>>> input = torch.randn(20, 16, 50, 100)
>>> output = m(input)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值