Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Stacked AutoEncoder linked correct or not?

So I am making a stacked autoencoder in keras but I am kinda new to keras.

So I would appreciate your help if you just check if my code is correct, especially how i am connecting one encoder to the next, the fit function(s) and the input and output of autoencoders 2 and 3.

Thank you in advance.

I am just gonna provide this link for people who dont know what a stacked autoencoder is, but know keras. http://ufldl.stanford.edu/wiki/index.php/Stacked_Autoencoders

# AutoEncoder 1
seq = Input(shape=(shape1,))
encoded_1 = Dense(shape2, activation='relu')(seq)
decoded_1 = Dense(shape1, activation='sigmoid')(encoded_1)

autoencoder_1 = Model(input=seq, output=decoded_1)
encoder_1 = Model(input=seq, output=encoded_1)
autoencoder_1.compile(optimizer='adadelta',
              loss='mse')

autoencoder_1.fit(x_train, x_train, epochs=20, batch_size=30)


# AutoEncoder 2
encoded_1.trainable = False
encoded_2 = Dense(shape3, activation='relu')(encoder_1.output)
decoded_2 = Dense(shape2, activation='relu')(encoded_2)

autoencoder_2 = Model(input=encoder_1.input, output=decoded_2)
encoder_2 = Model(input=encoder_1.input, output=encoded_2)


autoencoder_2.compile(optimizer='adadelta',
              loss='mse')

autoencoder_2.fit(x_train, encoder_1.predict(x_train), epochs=20, batch_size=30)


# AutoEncoder 3
encoded_2.trainable = False
encoded_3 = Dense(shape4, activation='relu')(encoder_2.output)
decoded_3 = Dense(shape3, activation='relu')(encoded_3)

autoencoder_3 = Model(input=encoder_2.input, output=decoded_3)
encoder_3 = Model(input=encoder_2.input, output=encoded_3)


autoencoder_3.compile(optimizer='adadelta',
              loss='mse')

autoencoder_3.fit(x_train, encoder_2.predict(x_train), epochs=20, batch_size=30)

Comments