Converting Keras model to Nengo

Hi, I’m trying to convert a Keras model to nengo using “nengo_dl.Converter” but i got this error : AttributeError: ‘TensorGraph’ object has no attribute ‘_layers’.
I’m using : nengo==3.0.0, nengo-dl==3.0.0, keras==2.4.3 and tensorflow==2.5.0
Please, could you tell me the cause of this error.

Hi @Cristale, and welcome to the Nengo forums. :smiley:

If I were to hazard a guess I would say that the NengoDL converter is not being provided with a TF model of the appropriate configuration. However, it is quite hard to determine if this is the case without looking at the code. If you could provide a code snippet or a minimum-working-example demonstrating this it’ll be easier to pinpoint the exact cause of this issue.

Hi @xchoo, thank you for your reply.
I’m testing this code Integrating a Keras model into a Nengo network — NengoDL 3.4.3.dev0 docs.
I got the error at this stage :

with net:
# we’ll disable some features we don’t need in this example, to improve
# the training speed
nengo_dl.configure_settings(stateful=False, use_loop=False)

minibatch_size = 20
with nengo_dl.Simulator(net, minibatch_size=minibatch_size) as sim:
# call compile and evaluate, as we did with the Keras model
“Test accuracy:”,
sim.evaluate(test_images, test_labels, verbose=0)[“probe_accuracy”],

I haven’t managed to recreate the exact error you are encountering (because the configuration you provided seems to generate other errors while trying to run the code), but I believe that the issue stems from the incompatibility between the versions of NengoDL and TensorFlow.

As noted on the NengoDL release notes, NengoDL 3.0.0 is only compatible with TF 2.0.0 and so it would likely not work with TF 2.5.0. If you want to use TF 2.5.0, I’d recommend (in a new Conda or python environment) upgrading your Nengo and NengoDL to the latest stable versions (NengoDL needs to be at least v3.4.2).

Problem solved with nengo 3.0.0, nengoDL 3.4.2 and tensorflow 2.2.0.
Thank you @xchoo.