tf.keras.models.load_model
    
    
      
    
    
      
      Stay organized with collections
    
    
      
      Save and categorize content based on your preferences.
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
Loads a model saved via model.save().
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 | 
  
  
    
      |  |  | 
  
| Args | 
|---|
| filepath | strorpathlib.Pathobject, 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 lambdadeserialization.
Whensafe_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 toTrue. | 
| Returns | 
|---|
| A Keras model instance. If the original model was compiled,
and the argument compile=Trueis set, then the returned model
will be compiled. Otherwise, the model will be left uncompiled. | 
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")
x = np.random.random((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.
  
  
 
  
    
    
      
       
    
    
  
  
  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. Some content is licensed under the numpy license.
  Last updated 2024-06-07 UTC.
  
  
  
    
      [null,null,["Last updated 2024-06-07 UTC."],[],[]]