tf.keras.models.load_model
Stay organized with collections
Save and categorize content based on your preferences.
Loads a model saved via save_model
.
tf.keras.models.load_model(
filepath, custom_objects=None, compile=True
)
Arguments |
filepath
|
One of the following:
- String, path to the saved model
h5py.File object from which to load the model
|
custom_objects
|
Optional dictionary mapping names
(strings) to custom classes or functions to be
considered during deserialization.
|
compile
|
Boolean, whether to compile the model
after loading.
|
Returns |
A Keras model instance. If an optimizer was found
as part of the saved model, the model is already
compiled. Otherwise, the model is uncompiled and
a warning will be displayed. When compile is set
to False, the compilation is omitted without any
warning.
|
Raises |
ImportError
|
if loading from an hdf5 file and h5py is not available.
|
IOError
|
In case of an invalid savefile.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.models.load_model\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/models/load_model) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/saving/save.py#L118-L154) |\n\nLoads a model saved via `save_model`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.models.load_model`](/api_docs/python/tf/keras/models/load_model)\n\n\u003cbr /\u003e\n\n tf.keras.models.load_model(\n filepath, custom_objects=None, compile=True\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|------------------|---------------------------------------------------------------------------------------------------------------------|\n| `filepath` | One of the following: \u003cbr /\u003e - String, path to the saved model - `h5py.File` object from which to load the model |\n| `custom_objects` | Optional dictionary mapping names (strings) to custom classes or functions to be considered during deserialization. |\n| `compile` | Boolean, whether to compile the model after loading. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Keras model instance. If an optimizer was found as part of the saved model, the model is already compiled. Otherwise, the model is uncompiled and a warning will be displayed. When `compile` is set to False, the compilation is omitted without any warning. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---------------|---------------------------------------------------------|\n| `ImportError` | if loading from an hdf5 file and h5py is not available. |\n| `IOError` | In case of an invalid savefile. |\n\n\u003cbr /\u003e"]]