TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/batch_norm_fold.py
def _delete_bn_for_non_subclassed_model(model: (tf.keras.Model, tf.keras.layers.Layer),
                                        bn_layer: tf.keras.layers.BatchNormalization):
    """
    Remove bn layer for those model which are not part of model subclassing

    :param model: model to delete bn layers from
    :param bn_layer: bn layer that should be removed
    """

    if isinstance(model, tf.keras.Sequential):
        _delete_bn_from_sequential(model, bn_layer)

    # We are expecting to find sequential model in functional model
    # or model subclassing in the elif statement
    elif isinstance(model, (tf.keras.layers.Layer, tf.keras.Model)):
        # pylint: disable=protected-access
        for layer in model._layers:
            if layer.submodules:
                _delete_bn_for_non_subclassed_model(layer, bn_layer)

    Remove bn layer for those model which are not part of model subclassing

    :param model: model to delete bn layers from
    :param bn_layer: bn layer that should be removed
    
Remove bn layer for those model which are not part of model subclassing
Remove bn layer for those model which are not part of model subclassing
def _delete_bn_for_non_subclassed_model(model: (tf.keras.Model, tf.keras.layers.Layer),
                                        bn_layer: tf.keras.layers.BatchNormalization):
    if isinstance(model, tf.keras.Sequential):
        _delete_bn_from_sequential(model, bn_layer)
    elif isinstance(model, (tf.keras.layers.Layer, tf.keras.Model)):
        for layer in model._layers:
            if layer.submodules:
                _delete_bn_for_non_subclassed_model(layer, bn_layer)
def _delete_bn_for_non_subclassed_model ( model : ( tf . keras . Model , tf . keras . layers . Layer ) , bn_layer : tf . keras . layers . BatchNormalization ) : if isinstance ( model , tf . keras . Sequential ) : _delete_bn_from_sequential ( model , bn_layer ) elif isinstance ( model , ( tf . keras . layers . Layer , tf . keras . Model ) ) : for layer in model . _layers : if layer . submodules : _delete_bn_for_non_subclassed_model ( layer , bn_layer )
Remove bn layer for those model which are not part of model subclassing
Remove bn layer for those model which are not part of model subclassing
"""
    Remove bn layer for those model which are not part of model subclassing

    :param model: model to delete bn layers from
    :param bn_layer: bn layer that should be removed
    """ # We are expecting to find sequential model in functional model # or model subclassing in the elif statement # pylint: disable=protected-access
model
(tf.keras.Model, tf.keras.layers.Layer)
model to delete bn layers from
model to delete bn layers from
bn_layer
tf.keras.layers.BatchNormalization
bn layer that should be removed
bn layer that should be removed