nengo-dl icon indicating copy to clipboard operation
nengo-dl copied to clipboard

TypeError fixes in converter.py->ConvertConcatenate

Open julvanu opened this issue 2 years ago • 1 comments

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.input_shape 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.

julvanu avatar Dec 14 '22 08:12 julvanu

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.

drasmuss avatar Dec 14 '22 13:12 drasmuss