ptrblck:

So how about we just store the filter weights as nn.Parameters in __init__ and just use the functional API ( F.conv2d ) in the forward method. Would that work at all? Sure! Since you’ve properly registered the filter weights in __init__ , they will be trained as long as they are used somewhere in the computation during your forward pass.


What about the following use case: I need a convolution layer (therefore learnable, unlike nn.MaxPool which you already mentionned) where the kernel_size parameter is the shape [height, width] of the input tensor, which is unknown at __init__ time. This results in a pooling effect, so that the output tensor has a NxCx1x1 shape.
Is it still possible to implement this, using the __init__ and forward behaviour?
(Thinking out loud: could this be replaced by a generic convolution in the __init__ and a global pooling layer in the forward method?)