Thank you! still have a problem with the exact implementation. Let’s say I have a code as follows:
class Model (nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.H  = 200
        self.W = 200
        self.conv = nn.Conv2d(1, 8, (1, 101), padding = (0, 50), bias = False)
        self.fc1 = nn.Linear(self.H * self.W , 1)        
    def forward(self, x):
      
        x = self.conv(x)
        x = F.relu(x)
        x = x.view(-1, self.H * self.W)
        x = torch.sigmoid(self.fc1(x))
        return x

Now Do I have to implement the ConstrainedConv2d like you did
class ConstrainedConv2d(nn.Conv2d):
    def forward(self, input):
        return F.conv2d(input, self.weight.clamp(min=-1.0, max=1.0), self.bias, self.stride,
                        self.padding, self.dilation, self.groups)

and replace my conv2D defined in the init by ConstrainedConv2D ? and if so how do I pass the the desired parameters to ConstrainedConv2D (input channel, outputChannel, kernel size …)