Custom kernel Conv2D

Hi! Can I have a kernel for a conv2d with some parameters trainable and some parameters not trainable?

Let s say if I have 1 kernel with dim 9x9 , can I have the firs 4x9 params trainable and the last 5x9 params not trainable?

Yes, you could create a custom nn.Parameter for the trainable part and use or torch.stack to create the weight tensor for the convolution. Once this is done, you could use the functional API via F.conv2d(input, weight, ...) to apply the convolution.
You could use a custom nn.Module for these operations, if it would fit your use case.

1 Like