How can I visualise the filters from the first layer of the network?

Hi, I want to compare the mentioned filters before training, halfway during training and after the training is completed. I have read some resources but I am struggling with implementation.

This is my network

ConvNet(
(conv1): Sequential(
(0): Conv2d(3, 16, kernel_size=(3, 3), stride=(1, 1))
(1): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(2): ReLU()
(3): Dropout(p=0.3, inplace=False)
)
(conv2): Sequential(
(0): Conv2d(16, 24, kernel_size=(4, 4), stride=(1, 1))
(1): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(2): ReLU()
(3): Dropout(p=0.3, inplace=False)
)
(conv3): Sequential(
(0): Conv2d(24, 32, kernel_size=(4, 4), stride=(1, 1))
(1): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(2): ReLU()
(3): Dropout(p=0.3, inplace=False)
)
(fc1): Sequential(
(0): Linear(in_features=26912, out_features=512, bias=True)
)
(fc2): Sequential(
(0): Linear(in_features=512, out_features=10, bias=True)
(1): Softmax(dim=1)
)
)

I have tried using this method here:

weight_tensor = model_gpu.conv1.weight.data.cpu()

a = weight_tensor[0] #

print(a)

print(a.size())

plt.imshow(a[0, …])

But I keep getting the error:

(0.0, 351.0, ‘0’, ‘black’, ‘center_baseline’, ‘right’, -7373694105942136849, None, None, 72.0, <weakref at 0x7f6aeb629f98; dead>, 1.2)

Try to transform the kernel to a numpy array via a = a.numpy() and make sure you are passing this array with the expected shapes for plt.imshow, which is either [height, width, channels] or [height, width].

1 Like

Yes that worked, I can now visualize the filters before training. Do you know anyway to visualize the filters during or after training has completed?

You could just call your function to visualize the filters during training and at the end, no?