Printing / saving autogenerators generated in Keras

I have this auto encoder:

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 to print or save the functions generated in encoding4. Basically, starting with a huge dataset, I would like to extract the functions generated by autoencoder after the tutorial part to get a limited view of my dataset.

could you help me?

+3


source to share


2 answers


You can do this by creating a "encoder" model:

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

      



This will use the same instances of layers that you trained with the autoencoder and should create this function if you use it in "output mode" like encoder.predict()

Hope this helps :)

+2


source


So basically by creating code like this:

 encoder = Model (input_dim,encoded4)
 encoded_input=Input(shape=(6,))

      

and then using:

 encoded_data=encoder.predict(data)

      

where the data in the function predict

is a dataset, the output is generated with



 print encoded_data

      

is a limited view of my dataset.

Right?

thank

+2


source







All Articles