To load a pre-trained Keras model from a saved file, you can use the load_model
function from the keras.models
module. Here’s how to do it:
# Import necessary libraries import keras from keras.models import load_model # Load the pre-trained Keras model from a file loaded_model = load_model('my_keras_model.h5') # Replace 'my_keras_model.h5' with the path to your model file # Now, you can use 'loaded_model' for predictions, fine-tuning, or other tasks
In this code:
- Import the necessary Keras libraries.
- Use the
load_model
function to load a Keras model from the specified file. Make sure to replace'my_keras_model.h5'
with the actual path to your model file.
After running this code, the loaded_model
will contain the architecture and weights of the pre-trained model, and you can use it for various tasks such as making predictions, fine-tuning, or further analysis.