Tensorflow clone_model with subclass model

Viewed 177

Is there a way to clone a subclass-based model in Tensorflow? For example, if I have the following model:

class MySequentialModel(tf.keras.Model):
  def __init__(self, name=None, **kwargs):
    super().__init__(**kwargs)

    self.dense_1 = FlexibleDense(out_features=3)
    self.dense_2 = FlexibleDense(out_features=2)
  def call(self, x):
    x = self.dense_1(x)
    return self.dense_2(x)

Then I train save, and load the model, when I try to clone it:

model = tf.keras.models.clone_model(original_model)

I get ValueError: Expected `model` argument to be a functional `Model` instance, but got a subclass model instead. Is there some other way to clone a model which is a subclass of tf.keras.Model?

0 Answers
Related