Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print/Save autoencoder generated features in Keras

I have this autoencoder:

input_dim = Input(shape=(10,))
encoded1 = Dense(30, activation = 'relu')(input_dim)
encoded2 = Dense(20, activation = 'relu')(encoded1)
encoded3 = Dense(10, activation = 'relu')(encoded2)
encoded4 = Dense(6, activation = 'relu')(encoded3)
decoded1 = Dense(10, activation = 'relu')(encoded4)
decoded2 = Dense(20, activation = 'relu')(decoded1)
decoded3 = Dense(30, activation = 'relu')(decoded2)
decoded4 = Dense(ncol, activation = 'sigmoid')(decoded3)
autoencoder = Model(input = input_dim, output = decoded4) 
autoencoder.compile(-...)
autoencoder.fit(...)

Now I would like print or save the features generate in encoded4. Basically, starting from a huge dataset I would like to extract the features generated by autoencoder, after the training part, to obtain a restricted representation of my dataset.

Could you help me?

like image 613
user3043636 Avatar asked Jul 31 '17 12:07

user3043636


1 Answers

You can do it by creating the "encoder" model:

encoder = Model(input = input_dim, output = encoded4)

This will use the same layers instances that you trained with the autoencoder and should be producing the feature if you use it in "inference mode" like encoder.predict()

I hope this helps :)

like image 199
Nassim Ben Avatar answered Nov 14 '22 23:11

Nassim Ben