import tensorflow as tf from tensorflow.python.keras.models import load_model model = load_model('my_model.h5') layer = model.get_layer('my_layer')
from tensorflow.python.keras import layers from tensorflow.python.keras.models import Input, Model input_tensor = Input(shape=(32,)) x = layers.Dense(64, activation='relu')(input_tensor) x = layers.Dense(64, activation='relu')(x) output_tensor = layers.Dense(10, activation='softmax')(x) model = Model(inputs=input_tensor, outputs=output_tensor) layer = model.get_layer('dense_1')In this example, we define a new model using Keras' functional API and retrieve a layer called 'dense_1' using the get_layer method. Package library: TensorFlow