Dear pytorchers,
Is it possible to compute a Circular convolution in pytorch?
My initial thought was to use Circular padding followed by regular convolution with no padding but it seems that Circular padding does not exist.
Dear pytorchers,
Is it possible to compute a Circular convolution in pytorch?
My initial thought was to use Circular padding followed by regular convolution with no padding but it seems that Circular padding does not exist.
You probably have to use a regular square convolution with a constraint on the weights to remove the corners of the convolution.
Could you elaborate on what do you mean by:
“constrain on the weights to remove the corners”
For example, a 2d convolution with kernel size 4 would have a 4x4 matrix of weights for each channel. Forcing the corners of this 4x4 matrix to be zero would give your convolution a nearly circular receptive field.
But maybe I have completely misunderstood what you mean by “circular convolution”.
Maybe you can draw some ideas from here: https://github.com/DmitryUlyanov/texture_nets/blob/master/src/SpatialCircularPadding.lua . It is easy to read.
You can use F.conv2d(F.pad(input, pad=(5,5,5,5), mode='circular'), kernel, padding=0)
for circular convolution. Btw, you sometimes cannot find the mode circular
for F.pad if you directly search in the help doc, but your can go to https://pytorch.org/docs/stable/nn.functional.html?highlight=pad#torch.nn.functional.pad