Solved by albanD in post #4 
              
              
                I simplified your code below: 
import torch
import torch.nn.functional as F
import numpy as np

img = torch.rand(1, 1, 512, 512)

kx, ky = 5, 5

# Goes from 1 channel to 1 channel
weight_h = torch.rand(1, 1, ky, 1)
weight_w = torch.rand(1, 1, 1, kx)

padx = kx // 2
pady = ky // 2

convY = F.conv2d(i…