Keras, using two pre-trained autoencoder models

Viewed 25

I'm looking to use two pre-trained autoencoder models and build a model on top with binary output. This is my code:

autoencoder = load_model("autoencoder.h5")

model1 = autoencoder
model2 = autoencoder
model1_out = model1.get_layer(index=7).output
model2_out = model2.get_layer(index=7).output

x = tf.keras.layers.concatenate([model1_out, model2_out])
x = Dense(400, activation='softmax')(x)
x = Dense(200, activation='softmax')(x) 
x = Dense(100, activation='softmax')(x) 
x = Dense(1, activation='sigmoid')(x) 

model=tf.keras.Model(inputs=[model1.input,model2.input],outputs=x)

model.compile(optimizer=Adam(learning_rate=0.001),loss='binary_crossentropy',
                                                       metrics=['accuracy'])

model.fit([X_train,X_train], y_train)

I get the following error:

ValueError: The list of inputs passed to the model contains the same input multiple times. 
   All inputs should only appear once.
   Received inputs=
   [<KerasTensor: shape=(None, 768) dtype=float32 (created by layer 'input_1')>, 
    <KerasTensor: shape=(None, 768) dtype=float32 (created by layer 'input_1')>]

Can somebody tell me what I am doing wrong?

Thanks!

0 Answers
Related