synsense / sinabs

A deep learning library for spiking neural networks which is based on PyTorch, focuses on fast training and supports inference on neuromorphic hardware.
https://sinabs.readthedocs.io
GNU Affero General Public License v3.0
80 stars 8 forks source link

[Feature] Add explicit error prompt for "make_config" method when passing a "chip_layers_ordering" argument without "dvs" in it. #134

Closed ssinhaleite closed 11 months ago

ssinhaleite commented 11 months ago

Description

When init a "DynapcnnCompatibleNetwork" instance, if you set the "dvs_input" arg to True, it will add an "DVSLayer" in the first place of the sequence.

Meanwhile, if you call the "make_config" method and pass a specific chip_layers_ordering list as its input argument, you must put a string "dvs" in the first place of this chip_layers_ordering list:

make_config(chip_layers_ordering=["dvs", 0, 1, 2, 3, 4, 5, 6, 7], device="speck2b:0")

if you just pass a list only contains the numerical layer index in it like:

make_config(chip_layers_ordering=[0, 1, 2, 3, 4, 5, 6, 7], device="speck2b:0")

you will get an obscure "IndexError: list index out of range".

Solution

Add a condition expression to check whether "dvs" in the "chip_layers_ordering" list

if self.dvs_input and chip_layers_ordering[0] != "dvs":
    raise Exception("self.dvs_input is True, but no \"dvs\" in chip_layers_ordering. Please add \"dvs\" into the chip_layers_ordering list.")