Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

python - Tensorflow clone_model with subclass model

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?

question from:https://stackoverflow.com/questions/66068938/tensorflow-clone-model-with-subclass-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...