Counting number of spikes for whole model

Hello Nengo Community,

I would like to know how to count the number of spikes of a model for a single inference.
What I mean is that once the model in trained for instance in the MNIST tutorial during the prediction I would like to count the number of spikes by the whole model for a single sample. One way would be to follow these posts Counting spikes and Spikes analysis. To calculate the spike for every single neuron in the model and then sum it up. Is there any other efficient way to do it?

Thank you in advance for your reply.

As far as I know, these are the ways to count the spikes for the whole model:

  • Probe the spikes for all ensembles, and sum
  • Create a node that counts the spikes for you

And these are the two approaches outlined in the posts you linked. I would recommend using the node approach since you can modify that to write to file rather than to memory, which should get around the memory constraints of probing everything in the network. Also, you can use the .all_ensembles parameter of a Nengo network to get a handle to all of the ensembles contained within the network, e.g.,

with nengo.Network() as model:
    ...

    for ens in model.all_ensembles:
        nengo.Connection(ens, spike_count_node)