TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/batch_norm_fold.py
def _delete_bn_from_sequential(layer: tf.keras.layers.Layer,
                               bn: tf.keras.layers.BatchNormalization):

    """
    This is the function for removing batch normalization layers that are layers of sequential model

    :param layer: model to obtain bn_layer that we want to remove
    :param bn: batch normalization layer that needs to be removed
    """

    layers_after_bn = []
    visited = False
    idx = None
    # pylint: disable=protected-access
    for index, inner_layer in enumerate(layer._layers):
        if visited:
            layers_after_bn.append(inner_layer)

        elif inner_layer == bn:
            visited = True
            idx = index

        elif inner_layer.submodules:
            _delete_bn_for_non_subclassed_model(inner_layer, bn)

    if visited and idx is not None:
        # pylint: disable=protected-access
        for _ in range(len(layer._layers) - idx):
            layer.pop()
        for layer_to_add in layers_after_bn:
            layer.add(layer_to_add)

    This is the function for removing batch normalization layers that are layers of sequential model

    :param layer: model to obtain bn_layer that we want to remove
    :param bn: batch normalization layer that needs to be removed
    
This is the function for removing batch normalization layers that are layers of sequential model
This is the function for removing batch normalization layers that are layers of sequential model
def _delete_bn_from_sequential(layer: tf.keras.layers.Layer,
                               bn: tf.keras.layers.BatchNormalization):
    layers_after_bn = []
    visited = False
    idx = None
    for index, inner_layer in enumerate(layer._layers):
        if visited:
            layers_after_bn.append(inner_layer)
        elif inner_layer == bn:
            visited = True
            idx = index
        elif inner_layer.submodules:
            _delete_bn_for_non_subclassed_model(inner_layer, bn)
    if visited and idx is not None:
        for _ in range(len(layer._layers) - idx):
            layer.pop()
        for layer_to_add in layers_after_bn:
            layer.add(layer_to_add)
def _delete_bn_from_sequential ( layer : tf . keras . layers . Layer , bn : tf . keras . layers . BatchNormalization ) : layers_after_bn = [ ] visited = False idx = None for index , inner_layer in enumerate ( layer . _layers ) : if visited : layers_after_bn . append ( inner_layer ) elif inner_layer == bn : visited = True idx = index elif inner_layer . submodules : _delete_bn_for_non_subclassed_model ( inner_layer , bn ) if visited and idx is not None : for _ in range ( len ( layer . _layers ) - idx ) : layer . pop ( ) for layer_to_add in layers_after_bn : layer . add ( layer_to_add )
This is the function for removing batch normalization layers that are layers of sequential model
This is the function for removing batch normalization layers that are layers of sequential model
"""
    This is the function for removing batch normalization layers that are layers of sequential model

    :param layer: model to obtain bn_layer that we want to remove
    :param bn: batch normalization layer that needs to be removed
    """ # pylint: disable=protected-access # pylint: disable=protected-access
layer
tf.keras.layers.Layer
model to obtain bn_layer that we want to remove
model to obtain bn_layer that we want to remove
bn
tf.keras.layers.BatchNormalization
batch normalization layer that needs to be removed
batch normalization layer that needs to be removed