# tf.keras.saving.load_model

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.14.0/keras/saving/saving_api.py#L176-L264) |

Loads a model saved via `model.save()`.

#### View aliases


**Main aliases**

[`tf.keras.models.load_model`](https://www.tensorflow.org/api_docs/python/tf/keras/saving/load_model)

<br />

    tf.keras.saving.load_model(
        filepath, custom_objects=None, compile=True, safe_mode=True, **kwargs
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `filepath` | `str` or `pathlib.Path` object, path to the saved model file. |
| `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. |
| `safe_mode` | Boolean, whether to disallow unsafe `lambda` deserialization. When `safe_mode=False`, loading an object has the potential to trigger arbitrary code execution. This argument is only applicable to the Keras v3 model format. Defaults to True. |

<br />

SavedModel format arguments:
options: Only applies to SavedModel format.
Optional [`tf.saved_model.LoadOptions`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/saved_model/LoadOptions) object that specifies
SavedModel loading options.

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A Keras model instance. If the original model was compiled, and the argument `compile=True` is set, then the returned model will be compiled. Otherwise, the model will be left uncompiled. ||

<br />

#### Example:

    model = tf.keras.Sequential([
        tf.keras.layers.Dense(5, input_shape=(3,)),
        tf.keras.layers.Softmax()])
    model.save("model.keras")
    loaded_model = tf.keras.saving.load_model("model.keras")
    x = tf.random.uniform((10, 3))
    assert np.allclose(model.predict(x), loaded_model.predict(x))

Note that the model variables may have different name values
(`var.name` property, e.g. `"dense_1/kernel:0"`) after being reloaded.
It is recommended that you use layer attributes to
access specific variables, e.g. `model.get_layer("dense_1").kernel`.