clone_model: Clone a model instance.

View source: R/model.R

clone_modelR Documentation

Clone a model instance.


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.


clone_model(model, input_tensors = NULL, clone_function = NULL)



Instance of Keras model (could be a functional model or a Sequential model).


Optional list of input tensors to build the model upon. If not provided, placeholders will be created.


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:

function(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).

keras documentation built on Aug. 16, 2023, 1:07 a.m.