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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…