Init Weights with Gaussian Kernels

is there a quick way to fill filters with Gauss filters + noise. i am familiar with …

def weights_init(m):
    if isinstance(m, nn.Conv2d):, 0.02), 0.001)

However I don’t know how to init s.t. we have gaussian filters.

Generate your filter with

copy over into is of shape: nOutputChannels x nInputChannels x kernelHeight x kernelWidth, so you have to generate nOutputChannels * nInputChannels, then make a numpy array of the same shape as and then copy:

generated_filters = ... # some scipy / numpy logic

I solved it as above answer as

        generated_filters = gaussian_filter(, sigma=0.5)

Thank you.

Gaussian is another word for normal distribution, so you can just use:

torch.nn.init.normal_(m.weight, 0, 0.5)

Assuming you want a standard deviation (or sigma) of 0.5 and a mean of 0.
Also see: torch.nn.init — PyTorch 1.8.1 documentation