def makeGaussian(size, fwhm=3, center=None):
x = np.arange(0, size, 1, float)
y = x[:, np.newaxis]
if center is None:
x0 = y0 = size // 2
else:
x0 = center[0]
y0 = center[1]
return np.exp(-4*np.log(2) * ((x-x0)**2 + (y-y0)**2) / fwhm**2)
g = makeGaussian(20, fwhm=5)
kernel = torch.FloatTensor(g)
kernel = torch.stack([kernel for i in range(3)]) # this stacks the kernel into 3 identical 'channels' for rgb images
batched_gaussian = Variable(torch.stack([kernel for i in range(batchSize)])) # stack kernel into batches
after_net = nnf.conv2d(out, batched_gaussian) # nnf is torch.nn.functional
You could do something like this, just make some filters and stack them into the appropriate shapes. I included the 2d gauss function from here just for clarity.
This will likely change the shape of your output images though so you will have to adjust padding, stride, etc. if that’s important.