Converting a simple ANN to SNN

I’ve found this simple RL model that solves the Gym CartPole-v0. I want to try to convert it to a spiking network just for a try.

I’m struggling to find a conversion for the GradientTape (they use GradientTape instead of fit). And even for the predict function… (error: input_1 data: should have rank 3 (batch_size, n_steps, dimensions), found rank 2)

How can I convert this simple model?

Hi @nrofis,

Can you provide a link or a snippet of the code you are using? Without that context, it’s hard to advise on how to achieve your goals.

In regards to converting an ANN to a spiking neural network, the NengoDL package can be used to convert TensorFlow / Keras models into spiking neural networks. We provide an example on how to do it here.

@xchoo, my bad… Forgot to attach the link to the original message…

Here it is: keras-io/actor_critic_cartpole.py at master · keras-team/keras-io · GitHub

I already read about NengoDL and saw that example. But for a guy like me, that has zero experience in Nengo DL, the gap from the well explained example to real life problem is huge :slight_smile:

@xchoo can you assist, please? The link is in my last comment

I am a quite busy with other work at the moment. I will get back to you when I am more available. Hopefully soon.

Just briefly, from my quick read of it, the GradientTape is a method which you use to train a network. This is distinct from the network definition itself.

NengoDL itself doesn’t natively support GradientTape, as NengoDL uses a different method for training and simulating ANNs and SNNs. With NengoDL, you’ll be able to convert the ANN network (just the network) to a spiking one, but you’ll want to figure out exactly what you want to achieve with the ANN before I can really advise further. As an example, here are some questions that you’ll need to address:

  • What do you want the network to learn / be trained?
  • What signals are available to the network?
  • How is the error signal (if any) is calculated?

Thank you. As you can see it solves the Gym CartPole-v0 environment, so all the questions have an answer. My problem is converting the GradientTape and the predict. If you can assist when you available, I will really appreciate that.