Как подать закодированный выход кодера на входы классификатора? - PullRequest
0 голосов
/ 19 ноября 2018

Я пытаюсь использовать AutoEncoder для повышения производительности классификатора.

Это AutoEncoder, который я написал, используя документацию keras для данных MNIST:

from keras.layers import Input, Dense
from keras.models import Model

# this is the size of our encoded representations
# 32 floats -> compression of factor 24.5, assuming the input is 784 floats
encoding_dim = 32

# this is our input placeholder
input_img = Input(shape=(784,))
# "encoded" is the encoded representation of the input
encoded = Dense(encoding_dim, activation='relu')(input_img)
# "decoded" is the lossy reconstruction of the input
decoded = Dense(784, activation='sigmoid')(encoded)

# this model maps an input to its reconstruction
autoencoder = Model(input_img, decoded)
# this model maps an input to its encoded representation
encoder = Model(input_img, encoded)
# create a placeholder for an encoded (32-dimensional) input
encoded_input = Input(shape=(encoding_dim,))
# retrieve the last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# create the decoder model
decoder = Model(encoded_input, decoder_layer(encoded_input))
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

autoencoder.fit(x_train, x_train,
                epochs=50,
                batch_size=256,
                shuffle=True,
                validation_data=(x_test, x_test))

Теперь я пытаюсь подключить его к классификатору. Используя этот вопрос , я написал:

x = encoder.output
# h = Dense(3, activation='relu', name='hidden')(x)
y = Dense(1, activation='sigmoid', name='predictions')(x)

classifier = Model(inputs=autoencoder.inputs, outputs=y)


# Compile model
classifier.compile(loss='binary_crossentropy', optimizer='adam',
                   metrics=['accuracy'])

# Fit the model
history = classifier.fit(x_train, y_train, 
                         epochs=10, 
                         batch_size=10,
                         validation_split=.1)

Во-первых, я не понимаю этот код. Во-вторых, я полагаю, что вывод y должен соответствовать 10 из 10 цифр, но я не могу установить 10, потому что я получаю ошибку.

В любом случае, точность вышеупомянутого классификатора очень низкая (10%)! Что-то не так в моем подходе?

...