machine learning - Python/Keras/Theano wrong dimensions for Deep Autoencoder -
i'm trying follow deep autoencoder keras example. i'm getting dimension mismatch exception, life of me, can't figure out why. works when use 1 encoded dimension, not when stack them.
exception: input 0 incompatible layer dense_18:
expected shape=(none, 128), found shape=(none, 32)*
the error on line decoder = model(input=encoded_input, output=decoder_layer(encoded_input))
from keras.layers import dense,input keras.models import model import numpy np # size of encoded representations encoding_dim = 32 #nput layer input_img = input(shape=(784,)) #encode layer # "encoded" encoded representation of input encoded = dense(encoding_dim*4, activation='relu')(input_img) encoded = dense(encoding_dim*2, activation='relu')(encoded) encoded = dense(encoding_dim, activation='relu')(encoded) #decoded layer # "decoded" lossy reconstruction of input decoded = dense(encoding_dim*2, activation='relu')(encoded) decoded = dense(encoding_dim*4, activation='relu')(decoded) decoded = dense(784, activation='sigmoid')(decoded) #model autoencoder = model(input=input_img, output=decoded) #seperate encoder model encoder = model(input=input_img, output=encoded) # create placeholder encoded (32-dimensional) input encoded_input = input(shape=(encoding_dim,)) # retrieve last layer of autoencoder model decoder_layer = autoencoder.layers[-1] # create decoder model decoder = model(input=encoded_input, output=decoder_layer(encoded_input)) #compiler autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
thanks hint marcin. turns out decoder layers need unrolled in order work.
# retrieve last layer of autoencoder model decoder_layer1 = autoencoder.layers[-3] decoder_layer2 = autoencoder.layers[-2] decoder_layer3 = autoencoder.layers[-1] # create decoder model decoder = model(input=encoded_input, output=decoder_layer3(decoder_layer2(decoder_layer1(encoded_input))))
Comments
Post a Comment