How to visualize convolutional filters with simulation framework based on Pytorch

Aarushi_Tiwari: <p>Hi,<br>
I’m new to Pytorch. I have trained a simple neural network with a pooling layer and then a convolutional layer to recognize images. I am using SpykeTorch, an open-source simulation framework based on PyTorch, to create my layers:</p>
<p>import SpykeTorch.snn as snn<br>
pool = snn.Pooling(kernel_size = 3, stride = 2)<br>
conv = snn.Convolution(in_channels=4, out_channels=20, kernel_size=30)</p>
<p>I want to visualize the learned convolutional filters that are passed over each input image. The snn.Convolution class is based on Pytorch’s nn.Module, but I’m not able to figure out how to visualize the filters. I have read past forum posts on this topic, saying to do weight = conv1.weight.data.numpy(), but my output tensor is of size [20, 4, 30, 30]. From what I understand, the 20 is the number of final feature maps in the layer after the filters are passed over the 4 input channels, not the number of filters, so I’m not sure how this approach works?</p>
<p>Side note: Spyketorch simulates Convolutional Spiking Neural Networks, so the input and output of each layer is in the form of a spike wave tensor of dimensions [time_step_max, feature_number, width, height] (time dimension replaces batch size).</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/b/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d_2_657x500.jpeg" alt="image" data-base62-sha1="jTWSpi8vUZk6fqopdcq3wrFTFPT" width="657" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/b/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d_2_657x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/8/b/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d_2_985x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b7c646a2578d3ef2ac3b05c211dad3ae89a8f2d.jpeg 2x" data-dominant-color="F6F4F4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1262×960 101 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>This is what a forward pass of the network looks like:</p>
<p>for iter in range(30):<br>
print(‘\rIteration:’, iter, end=“”)<br>
for data,_ in train_loader:<br>
for x in data:<br>
x = pool(x)<br>
p = conv(x)<br>
o, p = sf.fire(p, 20, return_thresholded_potentials=True)<br>
winners = sf.get_k_winners(p, kwta=1, inhibition_radius=0, spikes=o)<br>
stdp(x, p, o, winners)<br>
print()<br>
print(“Unsupervised Training is Done.”)</p>
<p>Thank you in advance!</p>

Aarushi_Tiwari: <p>Update: I am confused because the output of my convolution layer is (15,20,1,1), meaning there are 20 feature maps for each time stamp (represented by the 15) and also 20 filters? The input shape to the pooling layer is (15,4,62,62), so I would think that if there are 20 filters, there would be 80 output feature maps because each of the 20 filters would pass over each of the 4 channels so the output shape of the convolution layer is (15,80,1,1). It seems somehow the 4 channels are combined and the 20 filters really only go over 1 image per the 15 timesteps. Can someone explain how the 4 channels are brought together? Is it just a simple sum?</p>