<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/saving/saving_api.py#L125-L235) |

Loads a model saved via `model.save()` or from an Orbax checkpoint.

    tf.keras.models.load_model(
        filepath, custom_objects=None, compile=True, safe_mode=True
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Introduction to modules, layers, and models](https://www.tensorflow.org/guide/intro_to_modules) - [Migrate \`tf.feature_column\`s to Keras preprocessing layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) - [Migrate the SavedModel workflow](https://www.tensorflow.org/guide/migrate/saved_model) - [Migrating your TFLite code to TF2](https://www.tensorflow.org/guide/migrate/tflite) - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) | - [Save and load a model using a distribution strategy](https://www.tensorflow.org/tutorials/distribute/save_and_load) - [Distributed training with Keras](https://www.tensorflow.org/tutorials/distribute/keras) - [Save and load models](https://www.tensorflow.org/tutorials/keras/save_and_load) - [Multi-worker training with Keras](https://www.tensorflow.org/tutorials/distribute/multi_worker_with_keras) - [Transfer learning with TensorFlow Hub](https://www.tensorflow.org/tutorials/images/transfer_learning_with_hub) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `filepath` | `str` or `pathlib.Path` object, path to the saved model file or Orbax checkpoint directory. |
| `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 />

<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 = keras.Sequential([
        keras.layers.Dense(5, input_shape=(3,)),
        keras.layers.Softmax()])
    model.save("model.keras")
    loaded_model = keras.saving.load_model("model.keras")

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`.