Custom layer with specific matrix operation

kernel
Hi,
I try to make my own layer with fixed kernel. I prepare kernel manually like in figure.
I want to find product from input and my kernel. But, product operations are not usual, only on the black part. for white, ignored. I dont need make it trainable for this layer.

So, it’s possible use torch.nn.Conv2d?

Thanks.

I think you may directly set the conv_layer.weight.data as your own kernel, then fix this layer.

1 Like

Thank you for your help, its working.