Search code examples
pythonkerasdeep-learningface-recognitionautoencoder

using the encoder part of an autoencoder in keras


What i want is to get output of encoder (compressed data) to then do a face_recognition on it . After training this autoencoder i want to use the trained encoder.

so when i try to run the code i get this error: How can i solve the problem and extract only the trained encoder part of this autoencoder model ?

ValueError: Error when checking target: expected max_pooling2d_3 to have shape (8, 8, 64) but got array with shape (64, 64, 3)

Solution

  • What's happening is that your model output is the encoded part, and you are providing the image you will encode as target, which is correct for an autoencoder. What you need to do is to define

    autoencoder = Model(input_img, decoded)
    

    to train it and then use a separate encoded-like model to use the .predict method to obtain the reduced input.