How to get the encoded data from a retrained autoencoder?

Illustration
priyasingh - 2021-07-08T10:35:47+00:00
Question: How to get the encoded data from a retrained autoencoder?

How to get the encoded data from a retrained autoencoder?   Here is my example:   X = bodyfat_dataset; autoenc = trainAutoencoder(X); extract1= encode(autoenc,X)' %convert to a net work net = network(autoenc); Xpred = net(X); %how do i extract the encoded data. %tried this but it did not help extract2 = net.outputs{1}  

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

Here are two options you can use:
Option 1:
 
1. Run the code to train and retrain an autoencoder:
% Train a first sparse autoencoder with default settings.
autoenc = trainAutoencoder(X1);
% convert this autoencoder into a network:
net = network(autoenc);
% retrain autoencoder:
net = train(net,X2,X2);
2. Then use 'genFunction' to generate a function for the autoencoder network:
 
 
genFunction(net);
This will create a new function on the current folder called 'neural_function' that contains the code for the autoencoder 'net'.
 
The customer could then edit this function so that it outputs the output of layer 1 (a1) (I have attached an example of how the function will look like after the changes).
 
3. Finally, the encoded data can be obtained by calling 'neural_function' on the new data:
features = neural_function(X1);

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!