I am trying to freeze the transferred model and then clone it to another model and then I tried to remove the last layer and add a new layer and train it on my data but an error keeps emerging: this is my function:
def transfered_model_prep(new_model):
new_model.trainable=False
cloned_model=keras.models.clone_model(new_model)
cloned_model.set_weights(new_model.get_weights())
cloned_model.trainable=False
cloned_model1 = keras.models.Sequential(cloned_model.layers[:-1])
model2=cloned_model1.add((keras.layers.Dense(1, activation='sigmoid')(cloned_model.layers[0])))
model2.compile(loss="binary_crossentropy",
optimizer="adam",
metrics=["accuracy"])
return model2
and this error keeps popping when i activate the function:
ValueError: Exception encountered when calling layer "add" (type Add).
A merge layer should be called on a list of inputs. Received: inputs=Tensor("Placeholder:0", shape=(None, 32, 32, 128), dtype=float32) (not a list of tensors)
Call arguments received:
• inputs=tf.Tensor(shape=(None, 32, 32, 128), dtype=float32)