2

I have a 2d Gaussian filter h, and I have initialised a Conv2d filter with

conv_filter = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=(sigma))

I attempted to set the weights with

with torch.no_grad():
    conv_filter.weight = torch.nn.Parameter(torch.from_numpy(h).float())

But I get an error saying that 3 dimensions is expected for the weight. I expanded the dimension with a newaxis by

with torch.no_grad():
    conv_filter.weight = torch.nn.Parameter(torch.from_numpy(h[:,:, np.newaxis]).float())

but then I receive RuntimeError: expected stride to be a single integer value or a list of 1 values to match the convolution dimensions, but got stride=[1, 1]

I finally tried to set stride to be 1, but the line:

conv_filter = torch.nn.Conv2d(in_channels=1, out_channels=1, strides = 1, kernel_size=(sigma))

says that "strides" is an unexpected arguments, and changing the spelling to "stride" has no effect and still yields the same Runtime error message.

shao12138
  • 49
  • 6

0 Answers0