Dilation Parameter for conv layer

I wanted to create a filter for conv layer which has spacing in between the rows. The dilation parameter only allows same spacing between the consecutive rows of the filters.

I want to create a filter with varying spacing between the rows of the filter. For example, 3 spaces between the first and second row and 6 spaces between 2nd and 3rd row for a (3 x 3) filter. Is there a way this can be done in pytorch.

Thank you!

Yes it can be done. But you’ll have to 1) keep a separate weight tensor as parameters, 2) at each training loop build a larger containing weight, fill certain indices with the values from the former tensor with other entries set to 0, and 3) use the functional interface to compute the result.

Thank you for the reply. Im not sure I get your idea fully.

If we are talking about only one filter of size (3 x 3). It is randomly initialized by pytorch. How do I specify that this filter rows only be applied at certain index rows of the input.

Im sorry but I cant make sense of your answer. Could you please elaborate a bit. Thank you!

There is no option for that. What I meant is that you can build a large weight tensor so that it is able to contain the dilated weights, initialize it to all zeros, and copy each entry of your 3x3 weight tensor to the correct location in this larger weight tensor, and use this new weight tensor to get the results.

I have the same question as Jabberwocky, and I have tried the method as you described. If define a large kernel and set corresponding position as zero, the calculation is eqal to the large kernel instead of 3x3 kernel. Apparently, dilated convolution in PyTorch is not completed in this way since its calculation is 3x3 exactly.