tf.keras.models.clone_model
Stay organized with collections
Save and categorize content based on your preferences.
Clone any Model
instance.
tf.keras.models.clone_model(
model, input_tensors=None, clone_function=None
)
Model cloning is similar to calling a model on new inputs,
except that it creates new layers (and thus new weights) instead
of sharing the weights of the existing layers.
Arguments |
model
|
Instance of Model
(could be a functional model or a Sequential model).
|
input_tensors
|
optional list of input tensors or InputLayer objects
to build the model upon. If not provided,
placeholders will be created.
|
clone_function
|
Callable to be used to clone each layer in the target
model (except InputLayer instances). It takes as argument the layer
instance to be cloned, and returns the corresponding layer instance to
be used in the model copy. If unspecified, this callable defaults to
the following serialization/deserialization function:
lambda layer: layer.__class__.from_config(layer.get_config()) .
By passing a custom callable, you can customize your copy of the
model, e.g. by wrapping certain layers of interest (you might want to
replace all LSTM instances with equivalent
Bidirectional(LSTM(...)) instances, for example).
|
Returns |
An instance of Model reproducing the behavior
of the original model, on top of new inputs tensors,
using newly instantiated weights. The cloned model might behave
differently from the original model if a custom clone_function
modifies the layer.
|
Raises |
ValueError
|
in case of invalid model argument value.
|
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.clone_model\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/keras/models/clone_model) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/models.py#L366-L409) |\n\nClone any `Model` instance.\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.clone_model`](/api_docs/python/tf/keras/models/clone_model), \\`tf.compat.v2.keras.models.clone_model\\`\n\n\u003cbr /\u003e\n\n tf.keras.models.clone_model(\n model, input_tensors=None, clone_function=None\n )\n\nModel cloning is similar to calling a model on new inputs,\nexcept that it creates new layers (and thus new weights) instead\nof sharing the weights of the existing layers.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `model` | Instance of `Model` (could be a functional model or a Sequential model). |\n| `input_tensors` | optional list of input tensors or InputLayer objects to build the model upon. If not provided, placeholders will be created. |\n| `clone_function` | Callable to be used to clone each layer in the target model (except `InputLayer` instances). It takes as argument the layer instance to be cloned, and returns the corresponding layer instance to be used in the model copy. If unspecified, this callable defaults to the following serialization/deserialization function: `lambda layer: layer.__class__.from_config(layer.get_config())`. By passing a custom callable, you can customize your copy of the model, e.g. by wrapping certain layers of interest (you might want to replace all `LSTM` instances with equivalent `Bidirectional(LSTM(...))` instances, for example). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| An instance of `Model` reproducing the behavior of the original model, on top of new inputs tensors, using newly instantiated weights. The cloned model might behave differently from the original model if a custom clone_function modifies the layer. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------|\n| `ValueError` | in case of invalid `model` argument value. |\n\n\u003cbr /\u003e"]]