|View source on GitHub|
Loads a model saved via
Compat aliases for migration
See Migration guide for more details.
tf.keras.models.load_model( filepath, custom_objects=None, compile=True, options=None )
model = tf.keras.Sequential([ tf.keras.layers.Dense(5, input_shape=(3,)), tf.keras.layers.Softmax()]) model.save('/tmp/model') loaded_model = tf.keras.models.load_model('/tmp/model') x = tf.random.uniform((10, 3)) assert np.allclose(model.predict(x), loaded_model.predict(x))
Note that the model weights may have different scoped names after being loaded. Scoped names include the model/layer names, such as
"dense_1/kernel:0". It is recommended that you use the layer properties to access specific variables, e.g.
| || One of the following: |
| ||Optional dictionary mapping names (strings) to custom classes or functions to be considered during deserialization.|
| ||Boolean, whether to compile the model after loading.|
| || Optional |
| A Keras model instance. If the original model was compiled, and saved with the optimizer, then the returned model will be compiled. Otherwise, the model will be left uncompiled. In the case that an uncompiled model is returned, a warning is displayed if the |
| ||if loading from an hdf5 file and h5py is not available.|
| ||In case of an invalid savefile.|
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.