Hi kalivoda,
The problem is that when you pass your model to the nengo_dl.Converter()
it converts the sequential model into a functional model. From that point you will need to be referencing that converted model, not the original.
If you want to just reference the output layer it is a little simpler, because the output layer is automatically made into a probe. You can get that probe with…
output_probe = converter.outputs[converter.model.output]
If you want to probe a different layer then you can use your original model layers as the key to the converter.layers
layer_probe = nengo.Probe(converter.layers[model.layers[YOUR_LAYER_NUM].get_output_at(YOUR_TENSOR_NUMBER)])
The converter uses the same layer objects as the original model, so your output tensors will double. However, the ones you want to access will always be the ones at the end of the tensor list. So if your original layer only has one output tensor, then when get your output probe you can reference the [-1
] entry.
I’ve added a simple script showing how to access the output probe, and a probe on the second layer.
import nengo
import nengo_dl
import tensorflow as tf
# create your keras model
model = tf.keras.Sequential(
[
tf.keras.layers.Dense(units=64, activation="relu", input_shape=(784,)),
tf.keras.layers.Dense(units=64, activation="relu"),
tf.keras.layers.Dense(units=10, activation="relu"),
]
)
# convert to nengo_dl and swap activations to spiking ones
converter = nengo_dl.Converter(model, swap_activations={tf.nn.relu: nengo.SpikingRectifiedLinear()})
with converter.net as net:
# probe on our output layer
probe_output = converter.outputs[converter.model.output]
# probe on our second layer
probe_layer = nengo.Probe(converter.layers[model.layers[1].get_output_at(-1)])
with nengo.Simulator(converter.net) as sim:
# run our simulation for 1 sec
sim.run(1)
# print our probe data
print(sim.data[probe_output])
print(sim.data[probe_layer])
One final note…you mention you want to run a spiking model, to do this you will have to swap your activation functions with spiking versions. I did this in the above example. There will be a few more steps you may need to take to get the same performance. We recently updated our examples for this exact purpose, so I’ll forward you there for some more details.
https://www.nengo.ai/nengo-dl/examples/keras-to-snn.html