Hello,
I am trying to do as you suggest but i’m kinda stuck and here is a simple example.
import torch
from torch import nn
from scipy.ndimage import gaussian_filter
import numpy as np


def g_difference(image, kernel, sigma1=3, sigma2=5):
    channels_in, channels_out = (image.shape[1], image.shape[1])
    print(channels_out)
    diffs = gaussian_filter(image.cpu().detach().numpy(), sigma=sigma2) - gaussian_filter(image.cpu().detach().numpy() , sigma=sigma1)
    conv2d = nn.Conv2d(channels_in, channels_out, kernel_size=kernel, bias=False)
    with torch.no_grad():
        conv2d.weight = torch.nn.Parameter(torch.FloatTensor(diffs).cuda())
    return conv2d


x = torch.randn([1, 1, 1600, 500])

output = g_difference(x, 1)

print(output(x.cuda()).shape) #  the output is [1,1,1,1]