0

I have a stacked autoencoder that is structured like 500-250-100-50-100-250-500. I now want to take out the 50-dimensional hidden layer and use it to classify my input data in 2 classes using a softmax layer.

That means I need my autoencoder to compress my 500-dimensional input vectors from my training dataset into 50-dimensional vectors and use it to train the softmax layer. In addition to that I also need the 50-dimensional hidden layer.

How I would get the hidden layer: autoencoder.layers[3]

But how do I get the compressed 50-dimensional vectors of the 500-dimensional input vectors? I would need to get the output of that hidden layer when using autoencoder.predict(x_train).

0

1 Answer 1

1

If you want to have another output from a hidden layer, you can get the output and add it to a new model like this:

new_model = tf.keras.Model(inputs=autoencoder.input, outputs=[autoencoder.layers[3].output, autoencoder.output])

Then you can get the predictions like this:

hidden_layer_pred, last_layer_pred = new_model.predict(x_train)
Sign up to request clarification or add additional context in comments.

2 Comments

Why would I need the autoencoder.output in tf.keras.Model? Wouldn't autoencoder.layers[3].output suffice?
If you want both of them in a one model, you can do like this. But if just hidden layer is enough for you, yes you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.