TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/utils/common.py
def _submodule_handler_node_to_layer_map(
        cur_layer: (tf.keras.Model, tf.keras.layers.Layer),
        node_layer_map: typing.Dict) -> (typing.Dict, str, typing.List):
    """
    The utility to extract node_layer_map for the cur_layer submodule and
    provide the connectivity with the outer model.

    :param cur_layer: model to obtain node_layer_ref for
    :param node_layer_map: dictionary of node_layer_ref includes an item with submodule ref as
             first value index or first and second value index
    :return: return dictionary includes node_ref as a key,
        in_layers and out_layer as value for cur_layer,
        inbound node of the input layer and list of outbound nodes after input layer
    """

    # pylint: disable=too-many-locals

    # im stands for inner model
    im_node_layer_map = create_node_to_layer_map(cur_layer)

    im_input_layer = None
    im_node_input = None
    im_nodes_after_input_layer = []
    im_input_layer_succeeding_layers = []

    for node, (in_layers, out_layer) in node_layer_map.items():
        if out_layer == cur_layer:
            # iterating through inner model node_layer_map dict to find input_layer
            # and its inbound_node
            for im_node, (im_in_layers, im_out_layer) in im_node_layer_map.items():
                if im_in_layers is None:
                    im_input_layer = im_out_layer
                    im_node_input = im_node
            # iterating through inner model node_layer_map dict to find input layer
            # outbound nodes and its succeeding layers
            for im_node, (im_in_layers, im_out_layer) in im_node_layer_map.items():
                if im_in_layers == [im_input_layer]:
                    im_input_layer_succeeding_layers.append(im_out_layer)
                    im_nodes_after_input_layer.append(im_node)
            # If there are more than one layer which input layer goes to in inner model,
            # we need to build a connection between incoming layer of cur layer
            # and inner model input layer (branch will not be considered in pattern)
            if len(im_input_layer_succeeding_layers) > 1:
                node_layer_map.update({node: [in_layers, im_input_layer]})
            # otherwise we need to build a connection between incoming layer of cur layer
            # and succeeding layers to inner model input layer
            elif len(im_input_layer_succeeding_layers) == 1:
                node_layer_map.update({node: [in_layers, im_input_layer_succeeding_layers[0]]})
        elif in_layers and cur_layer in in_layers:
            im_last_layers = _find_last_layers(cur_layer)
            node_layer_map.update({node: [im_last_layers, out_layer]})

    return im_node_layer_map, im_node_input, im_nodes_after_input_layer

    The utility to extract node_layer_map for the cur_layer submodule and
    provide the connectivity with the outer model.

    :param cur_layer: model to obtain node_layer_ref for
    :param node_layer_map: dictionary of node_layer_ref includes an item with submodule ref as
             first value index or first and second value index
    :return: return dictionary includes node_ref as a key,
        in_layers and out_layer as value for cur_layer,
        inbound node of the input layer and list of outbound nodes after input layer
    
The utility to extract node_layer_map for the cur_layer submodule and
provide the connectivity with the outer model.
The utility to extract node_layer_map for the cur_layer submodule and provide the connectivity with the outer model .
def _submodule_handler_node_to_layer_map(
        cur_layer: (tf.keras.Model, tf.keras.layers.Layer),
        node_layer_map: typing.Dict) -> (typing.Dict, str, typing.List):
    im_node_layer_map = create_node_to_layer_map(cur_layer)
    im_input_layer = None
    im_node_input = None
    im_nodes_after_input_layer = []
    im_input_layer_succeeding_layers = []
    for node, (in_layers, out_layer) in node_layer_map.items():
        if out_layer == cur_layer:
            for im_node, (im_in_layers, im_out_layer) in im_node_layer_map.items():
                if im_in_layers is None:
                    im_input_layer = im_out_layer
                    im_node_input = im_node
            for im_node, (im_in_layers, im_out_layer) in im_node_layer_map.items():
                if im_in_layers == [im_input_layer]:
                    im_input_layer_succeeding_layers.append(im_out_layer)
                    im_nodes_after_input_layer.append(im_node)
            if len(im_input_layer_succeeding_layers) > 1:
                node_layer_map.update({node: [in_layers, im_input_layer]})
            elif len(im_input_layer_succeeding_layers) == 1:
                node_layer_map.update({node: [in_layers, im_input_layer_succeeding_layers[0]]})
        elif in_layers and cur_layer in in_layers:
            im_last_layers = _find_last_layers(cur_layer)
            node_layer_map.update({node: [im_last_layers, out_layer]})
    return im_node_layer_map, im_node_input, im_nodes_after_input_layer
def _submodule_handler_node_to_layer_map ( cur_layer : ( tf . keras . Model , tf . keras . layers . Layer ) , node_layer_map : typing . Dict ) -> ( typing . Dict , str , typing . List ) : im_node_layer_map = create_node_to_layer_map ( cur_layer ) im_input_layer = None im_node_input = None im_nodes_after_input_layer = [ ] im_input_layer_succeeding_layers = [ ] for node , ( in_layers , out_layer ) in node_layer_map . items ( ) : if out_layer == cur_layer : for im_node , ( im_in_layers , im_out_layer ) in im_node_layer_map . items ( ) : if im_in_layers is None : im_input_layer = im_out_layer im_node_input = im_node for im_node , ( im_in_layers , im_out_layer ) in im_node_layer_map . items ( ) : if im_in_layers == [ im_input_layer ] : im_input_layer_succeeding_layers . append ( im_out_layer ) im_nodes_after_input_layer . append ( im_node ) if len ( im_input_layer_succeeding_layers ) > 1 : node_layer_map . update ( { node : [ in_layers , im_input_layer ] } ) elif len ( im_input_layer_succeeding_layers ) == 1 : node_layer_map . update ( { node : [ in_layers , im_input_layer_succeeding_layers [ 0 ] ] } ) elif in_layers and cur_layer in in_layers : im_last_layers = _find_last_layers ( cur_layer ) node_layer_map . update ( { node : [ im_last_layers , out_layer ] } ) return im_node_layer_map , im_node_input , im_nodes_after_input_layer
The utility to extract node_layer_map for the cur_layer submodule and
provide the connectivity with the outer model.
The utility to extract node_layer_map for the cur_layer submodule and provide the connectivity with the outer model .
"""
    The utility to extract node_layer_map for the cur_layer submodule and
    provide the connectivity with the outer model.

    :param cur_layer: model to obtain node_layer_ref for
    :param node_layer_map: dictionary of node_layer_ref includes an item with submodule ref as
             first value index or first and second value index
    :return: return dictionary includes node_ref as a key,
        in_layers and out_layer as value for cur_layer,
        inbound node of the input layer and list of outbound nodes after input layer
    """ # pylint: disable=too-many-locals # im stands for inner model # iterating through inner model node_layer_map dict to find input_layer # and its inbound_node # iterating through inner model node_layer_map dict to find input layer # outbound nodes and its succeeding layers # If there are more than one layer which input layer goes to in inner model, # we need to build a connection between incoming layer of cur layer # and inner model input layer (branch will not be considered in pattern) # otherwise we need to build a connection between incoming layer of cur layer # and succeeding layers to inner model input layer
return dictionary includes node_ref as a key,
in_layers and out_layer as value for cur_layer,
inbound node of the input layer and list of outbound nodes after input layer
return dictionary includes node_ref as a key in_layers and out_layer as value for cur_layer inbound node of the input layer and list of outbound nodes after input layer
cur_layer
(tf.keras.Model, tf.keras.layers.Layer)
model to obtain node_layer_ref for
model to obtain node_layer_ref for
node_layer_map
typing.Dict
dictionary of node_layer_ref includes an item with submodule ref as
first value index or first and second value index
dictionary of node_layer_ref includes an item with submodule ref as first value index or first and second value index