nengo / nengo-dl

Deep learning integration for Nengo
https://www.nengo.ai/nengo-dl
Other
88 stars 22 forks source link

TypeError fixes in converter.py->ConvertConcatenate #230

Open julvanu opened 1 year ago

julvanu commented 1 year ago

I wanted to convert a Keras model using the nengo_dl Converter class as proposed in the docu: https://www.nengo.ai/nengo-dl/examples/keras-to-snn.html#Converting-a-Keras-model-to-a-Nengo-network

Thereby, I ran into two bugs so far. The issue seems to be, that nengo_dl Converter is not prepared for a Concatenate layer to get a list of length 1 as input. Here is my approach to fix it.

  1. _self.inputshape in ConvertConcatenate returns EITHER a list of tuples OR just a tuple, though the convert function in ConvertConcatenate assumes that what is returned is always a list of tuples. Therefore, in specific cases as in mine you get a TypeError.

  2. If I get it right, this for loop at line 1242 assumes self.layer.input to always be a list of KerasTensors. Though, if the Concatenate layer gets only one KerasTensor as input, self.layer.input is not a list but just that KerasTensor. Keras layers work on symbolic inputs/outputs meaning their "KerasTensor" do not hold actual data and therefore do not implement functions like "\_len___". That is why in that case we gete a TypeError as well.

drasmuss commented 1 year ago

Hi @julvanu, thanks for the bug fix! Could you add a test case for converting a concatenate layer with a single input? You can see the current concatenate test here https://github.com/nengo/nengo-dl/blob/master/nengo_dl/tests/test_converter.py#L136, probably we just want to parametrize that to add a single input case. I can also add that in myself when I get to reviewing it if you don't get the chance. We're a little backed up on NengoDL work currently, but I'd anticipate getting to this early in the new year.