So basically I’d like to define a layer that takes in a fixed kernel.
For example:
class FixedConv2d(nn.Module):
 def __init__(self):
     super(FixedConv2d, self).__init__()
     f = np.random.rand(5, 5).astype(np.float32)
     f = f.reshape(1, 1, f.shape[0], f.shape[1])
     f = np.repeat(f, 100, axis=1)
     f = np.repeat(f, 100, axis=0)
     self.f = nn.Parameter(data=torch.FloatTensor(f), requires_grad=False)

 def forward(self, x):
     return F.conv2d(x, self.f)

I added this module to my network using nn.Sequential(). I don’t want it to be optimized by the optimizer. When I pass the paramters of my network (mode.paramters()) to the optimizer, it complains because self.f doesn’t require grad.
I’m wondering what’s the correct way of doing this?
Thanks!