TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/utils/common.py
def _get_residing_model_of_layer(model: tf.keras.Model, layer: tf.keras.layers.Layer) -> typing.Union[tf.keras.Model,
                                                                                                      None]:
    """
    Get the model in which the layer resides, given a top level model. The residing model could be the topmost level
    model itself, or a submodel inside the topmost model.
    :param model: Top level model
    :param layer: Layer to get residing model of
    return: Residing model of layer
    """
    if layer in model.layers:
        return model

    # Iterate through layers of current model level and recursively call into any layer that is a model
    for inner_layer in model.layers:
        if isinstance(inner_layer, tf.keras.models.Model):
            residing_model = _get_residing_model_of_layer(inner_layer, layer)
            if residing_model is not None:
                return residing_model
    return None

    Get the model in which the layer resides, given a top level model. The residing model could be the topmost level
    model itself, or a submodel inside the topmost model.
    :param model: Top level model
    :param layer: Layer to get residing model of
    return: Residing model of layer
    
Get the model in which the layer resides, given a top level model. The residing model could be the topmost level
model itself, or a submodel inside the topmost model.
Get the model in which the layer resides given a top level model . The residing model could be the topmost level model itself or a submodel inside the topmost model .
def _get_residing_model_of_layer(model: tf.keras.Model, layer: tf.keras.layers.Layer) -> typing.Union[tf.keras.Model,
                                                                                                      None]:
    if layer in model.layers:
        return model
    for inner_layer in model.layers:
        if isinstance(inner_layer, tf.keras.models.Model):
            residing_model = _get_residing_model_of_layer(inner_layer, layer)
            if residing_model is not None:
                return residing_model
    return None
def _get_residing_model_of_layer ( model : tf . keras . Model , layer : tf . keras . layers . Layer ) -> typing . Union [ tf . keras . Model , None ] : if layer in model . layers : return model for inner_layer in model . layers : if isinstance ( inner_layer , tf . keras . models . Model ) : residing_model = _get_residing_model_of_layer ( inner_layer , layer ) if residing_model is not None : return residing_model return None
Get the model in which the layer resides, given a top level model.
Get the model in which the layer resides given a top level model .
"""
    Get the model in which the layer resides, given a top level model. The residing model could be the topmost level
    model itself, or a submodel inside the topmost model.
    :param model: Top level model
    :param layer: Layer to get residing model of
    return: Residing model of layer
    """ # Iterate through layers of current model level and recursively call into any layer that is a model
model
tf.keras.Model
Top level model
Top level model
layer
tf.keras.layers.Layer
Layer to get residing model of
return: Residing model of layer
Layer to get residing model of return : Residing model of layer