def forward(self, x):
x = F.relu(self.conv1(x))
x = F.max_pool2d(x, 2, 2)
x = F.relu(self.conv2(x))
x = F.max_pool2d(x, 2, 2)
x = x.view(-1,4*4*80)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return F.log_softmax(x, dim=1)
and then visualize it with e.g. matplotlib.pyplot.imshow.
Note that filters might be multi-dimensional, so you might need to plot each channel in a separate subplot.
In your model, self.conv1 contains one input channel, so you should be able to visualize each filer next to each other.
You could interpolate the filters first e.g. via F.interpolate(..., mode='nearest').
If you specify mode='nearest', it’ll make sure to repeat the values instead of e.g. interpolate them linearly.
Alternatively you could also use matplotlib or PIL to store the filters, which would provide an argument for the desired shape.