Solved by ptrblck in post #2 
              
              
                Your kernel shape in kn is wrong, as nn.Conv2d uses a weight with the shape [out_channels, in_channels, height, width]. 
This code should work: 
kn = torch.Tensor([[1 ,0, -1],[2, 0 ,-2], [1, 0 ,-1]]).unsqueeze(0).unsqueeze(0)

class ConvolutionalNetwork(nn.Module):
    def __init__(self):
        su…