conv2d函数中dilation参数:int or tuple

如图,摘自ERFNet中,在很多Net中都会出现dilation是tuple的情况:

nn.Conv2d(chann, chann, (1,3), stride=1, padding=(0,1*dilated), bias=True, dilation = (1, dilated))

在conv文件中指出,dilation可以是int或者tuple,所以dilation可能出现,dilation=2或dilation=(2,1)等情况:

 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1

根据conv.py文件可以看出,dilation,扩张操作:控制kernel点(卷积核点)的间距

"""
attr:`dilation` controls the spacing between the kernel points; also known as the à trous algorithm.
    It is harder to describe, but this `link`_ has a nice visualization of what :attr:`dilation` does.

The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:
    - a single ``int`` -- in which case the same value is used for the height and width dimensions
    - a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension, 
    and the second `int` for the width dimension
"""

即对于kernel_size,stride,padding,dilation这四个参数而言,下面的描述都成立:

一个单一的int的情况下,相同的值被用于高度和宽度维度
一个两个int的`tuple'--在这种情况下,第一个`int'用于高度维度,第二个`int'用于宽度维度

 所以,这段代码表示,当dilation=2时,padding=(0,2),dilation=(1,2),图示为:

nn.Conv2d(chann, chann, (1,3), stride=1, padding=(0,1*dilated), bias=True, dilation = (1, dilated))

嗯自己的理解是这样的 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nn.Conv2d()是PyTorch用于实现卷积层的函数。下面是该函数参数详解: - in_channels(int):输入图像的通道数。例如RGB图像的通道数为3。 - out_channels(int):输出图像的通道数,也就是卷积核的数量。 - kernel_size(int or tuple):卷积核的大小,可以是一个整数,如3,表示3x3的卷积核,也可以是一个元组,如(3, 3),表示3x3的卷积核。 - stride(int or tuple, optional):卷积核的步长,可以是一个整数,如1,表示步长为1,也可以是一个元组,如(2, 2),表示步长为2。 - padding(int or tuple, optional):填充的大小,可以是一个整数,如1,表示在输入的每一条边补充1个0值像素,也可以是一个元组,如(1, 1),表示在输入的每一条边补充1个0值像素。 - dilation(int or tuple, optional):卷积核的空洞大小,可以是一个整数,如2,表示卷积核里面间隔1个像素,也可以是一个元组,如(2, 2),表示卷积核里面间隔2个像素。 - groups(int, optional):输入和输出之间的连接数,当groups=1时,表示普通的卷积操作,当groups=in_channels时,表示对输入的每个通道分别进行卷积操作,当groups=out_channels时,表示对输出的每个通道分别进行卷积操作。 - bias(bool, optional):是否使用偏置项,默认为True,即使用偏置项。 以上是nn.Conv2d()的主要参数,使用时需要根据具体的任务和数据进行适当的调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值