From 430af988bef9ff8787d53bc50b0f81474384a200 Mon Sep 17 00:00:00 2001 From: Willian-Girao Date: Tue, 29 Oct 2024 22:39:46 +0100 Subject: [PATCH] DONE - DVS node not given constructor of DynapcnnNetwork executing wihtout errors --- .../backend/dynapcnn/dynapcnn_layer_utils.py | 21 ++++++++++--------- .../backend/dynapcnn/sinabs_edges_handler.py | 4 ++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sinabs/backend/dynapcnn/dynapcnn_layer_utils.py b/sinabs/backend/dynapcnn/dynapcnn_layer_utils.py index faeef269..491093b7 100644 --- a/sinabs/backend/dynapcnn/dynapcnn_layer_utils.py +++ b/sinabs/backend/dynapcnn/dynapcnn_layer_utils.py @@ -271,16 +271,17 @@ def construct_destination_map(dcnnl_map: Dict[int, Dict]) -> Dict[int, List[int] """ destination_map = dict() for layer_index, layer_info in dcnnl_map.items(): - destination_indices = [] - none_counter = 0 - for dest in layer_info["destinations"]: - if (dest_idx := dest["destination_layer"]) is None: - # For `None` destinations use unique negative index - none_counter += 1 - destination_indices.append(-none_counter) - else: - destination_indices.append(dest_idx) - destination_map[layer_index] = destination_indices + if 'dvs_layer' not in layer_info: # only called for `DynapcnnLayer` instances (skip DVS layer). + destination_indices = [] + none_counter = 0 + for dest in layer_info["destinations"]: + if (dest_idx := dest["destination_layer"]) is None: + # For `None` destinations use unique negative index + none_counter += 1 + destination_indices.append(-none_counter) + else: + destination_indices.append(dest_idx) + destination_map[layer_index] = destination_indices # update mapper if a DVS layer exists. update_destination_map_with_dvs(dcnnl_map, destination_map) diff --git a/sinabs/backend/dynapcnn/sinabs_edges_handler.py b/sinabs/backend/dynapcnn/sinabs_edges_handler.py index f524f784..018dcf58 100644 --- a/sinabs/backend/dynapcnn/sinabs_edges_handler.py +++ b/sinabs/backend/dynapcnn/sinabs_edges_handler.py @@ -183,6 +183,7 @@ def collect_dynapcnn_layer_info( dynapcnn_layer_info, indx_2_module_map, node_2_layer_map, + nodes_io_shapes, ) # TODO - handle dvs->pooling connections. @@ -405,6 +406,7 @@ def add_or_update_dvs_to_entry( dynapcnn_layer_info: Dict[int, Dict[int, Dict]], indx_2_module_map: Dict[int, nn.Module], node_2_layer_map: Dict[int, int], + nodes_io_shapes: Dict[int, Dict[str, Tuple[Size, Size]]], ) -> None: """ Initiate or update dict to hold information for a DVS Layer configuration based on a "dvs-weight" edges. Change `dynapcnn_layer_info` in-place. If a entry for the DVS node exists the function will add a new entry @@ -420,6 +422,7 @@ def add_or_update_dvs_to_entry( indx_2_module_map (dict): Maps node IDs of the graph as `key` to their associated module as `value` node_2_layer_map (dict): Maps each node ID to the ID of the layer it is assigned to. Will be updated in-place. + nodes_io_shapes (dict): Map from node ID to dict containing node's in- and output shapes """ assert isinstance(indx_2_module_map[edge[0]], DVSLayer), f'Source node in edge {edge} is of type {type(DVSLayer)} (it should be a DVSLayer instance).' @@ -432,6 +435,7 @@ def add_or_update_dvs_to_entry( # Init. entry for a DVS layer using its configuration dict. dynapcnn_layer_info[layer_id] = { + "is_entry_node": True, "dvs_layer": True, "node_id": edge[0], # TODO - GraphTracer not populating I/O shape for DVS yet.