Dilation in ConvLayer class

Hi all,
I’ve been working with dilation convolutional layer for a while now, and noticed that the ResBlock class doesn’t handle dilation well when the input and output of the layer isn’t the same size.
I’ve looked at the code and traced it back to the residual layer connection which should have the same dilation as the other branch, but with a different padding as it has different size kernel.
The automatic calculation of padding in the ConvLayer class takes into account the kernel size, but not the dilation.
I’ve created a hot-fix for this by changing the beginning of the ConvLayer:

class ConvLayer(nn.Sequential):
    "Create a sequence of convolutional (`ni` to `nf`), ReLU (if `use_activ`) and `norm_type` layers."
    def __init__(self, ni, nf, ks=3, stride=1, padding=None, bias=None, ndim=2, norm_type=NormType.Batch, bn_1st=True,
                 act_cls=defaults.activation, transpose=False, init='auto', xtra=None, bias_std=0.01, dilation=1, **kwargs):
        if padding is None: padding = ((ks-1)//2*dilation if not transpose else 0)

Hope this helps others :slight_smile:

1 Like