Torch conv2d using handmade kernel


The problem or idea, whatever, is: i want to put my own kernel/filer to conv2d. For example, i have generator of kernels and i want to apply it to batch of images. In tensorflow there are tf.nn.conv2d which have “filter” as input, but these “filters” are of size [in, out, height, width]. No batch size. But i need that. Is there anything like that in pytorch?

Tried to look for answer for this problem too long and found only solution is to make my own conv layer but i hoped that there are already such a thing in pytorch. Or am i wrong?

Thanks in advance


The nn.Conv2D() layer has a .weight and a .bias that contain the weights and bias used by the convolution.
As you can see in the module’s implementation here, it’s just using the functional interface and give these weights and biases to it. You can use directly this functional interface if you want and give custom weights and biases to it :slight_smile:

So, i could use this Functional conv2d using something like this:

F.conv2d(input, weight, bias, stride, padding, dilation, groups)? Using my own weight, bias etc?

Yes that’s what it’s for :slight_smile:

1 Like