Spiking Activation

Shivani_Sri_Varshini: <p>I’m trying to implement spiking activation on CNN. However, it is results dimension errors. I’m tried snntorch, pytorch_spiking etc.</p>
<p>I’m unable to implement snn activation</p>
<p>Please kindly provide any source for snn activation which works with pytorch cnn</p>

Jegp: <p>I’m the maintainer of <a href="https://github.com/norse/norse" class="inline-onebox" rel="noopener nofollow ugc">GitHub - norse/norse: Deep learning with spiking neural networks (SNNs) in PyTorch.</a><br>
We have examples on CNN integration directly in the REAME <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>

Shivani_Sri_Varshini: <p><a class="mention" href="/u/jegp">@Jegp</a>, I have tried Norse also. still I’m getting dimension errors</p>
<p>I have passed 3D input for text [batch_size, sequence_length,embedding_dim]. with this input I got dimension errors then I converted the input to [batch_size, hidden_dim].I observed the batch_size is changing after applying spiking activation</p>

Jegp: <p>Did you try the example in the README? The dimensionality should <em>not</em> change after an activation layer. Sounds like something else could be happening.</p>

Shivani_Sri_Varshini: <p><a class="mention" href="/u/jegp">@Jegp</a>, It’s working fine. I’m getting 3 different outputs from LIFCell(). What those outputs are related too?</p>

Jegp: <p>Happy to hear <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>The outputs of the LIFCell are shaped exactly like its inputs. So the LIF* modules are simply just stateful activation functions.</p>

Shivani_Sri_Varshini: <p>I observed that all spikes are zero’s and not  showing any impact on the model</p>

Shivani_Sri_Varshini: <p>For the example code which is mentioned in norse documentation/github</p>
<p>import torch, torch.nn as nn<br>
from norse.torch import LICell             # Leaky integrator<br>
from norse.torch import LIFCell            # Leaky integrate-and-fire<br>
from norse.torch import SequentialState    # Stateful sequential layers</p>
<p>model = SequentialState(<br>
nn.Conv2d(1, 20, 5, 1),      # Convolve from 1 → 20 channels<br>
LIFCell(),                   # Spiking activation layer<br>
nn.MaxPool2d(2, 2),<br>
nn.Conv2d(20, 50, 5, 1),     # Convolve from 20 → 50 channels<br>
LIFCell(),<br>
nn.MaxPool2d(2, 2),<br>
nn.Flatten(),                # Flatten to 800 units<br>
nn.Linear(800, 10),<br>
LICell(),                    # Non-spiking integrator layer<br>
)</p>
<p>data = torch.randn(8, 1, 28, 28) # 8 batches, 1 channel, 28x28 pixels<br>
output, state = model(data)</p>
<p>print(output)</p>
<p>tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],<br>
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], grad_fn=)</p>
<p>Even this is resulting output with zero’s</p>

Jegp: <p>The problem with spiking neural networks is that if they don’t spike, the subsequent layer only receives 0’s. Which means your output will be zero.</p>
<p>What happens if you, for instance, set your data<br>
<code>data = torch.randn(8, 1, 28, 28) + 100</code> ?</p>