re-train a pre-trained autoencoder

조회 수: 2 (최근 30일)
cedric MAGUETA RUIVO
cedric MAGUETA RUIVO 2016년 8월 19일
댓글: Giuseppe Bisazza 2021년 10월 1일
Hello, I want to retrain an autoencoder with a different set of images. autoencoder classe seems to not allowed this, so i transform my autoencoder into a classical neural network (with network function). but now i need to encode my data to train the next layer. How can i do that?

답변 (1개)

Grzegorz Knor
Grzegorz Knor 2017년 7월 17일
편집: Grzegorz Knor 2017년 7월 18일
To encode data from retrained network you need to create new network, which contains only encoder layer. Please see the code (it is based on TrainSparseAutoencoderExample):
% load dataset
X = abalone_dataset;
% split it into two parts
X1 = X(:,1:2085);
X2 = X(:,2086:end);
% Train a first sparse autoencoder with default settings.
autoenc = trainAutoencoder(X1);
% Reconstruct inputs.
XReconstructed1 = predict(autoenc,X1);
% Compute the mean squared reconstruction error.
mseError1 = mse(X1-XReconstructed1)
% convert existed autoenc to network:
net = network(autoenc);
% retrain autoenc(net):
net = train(net,X2,X2);
% Reconstruct inputs.
XReconstructed2 = net(X2);
% Compute the mean squared reconstruction error.
mseError2 = mse(X2-XReconstructed2)
% compare biases
figure
bar([net.b{1} autoenc.EncoderBiases])
% compare weights
figure
plot(autoenc.EncoderWeights-net.IW{1})
% extract features from autoencoder
features1 = encode(autoenc,X1);
% create encoder form trained network
encoder = network;
% Define topology
encoder.numInputs = 1;
encoder.numLayers = 1;
encoder.inputConnect(1,1) = 1;
encoder.outputConnect = 1;
encoder.biasConnect = 1;
% Set values for labels
encoder.name = 'Encoder';
encoder.layers{1}.name = 'Encoder';
% Copy parameters from input network
encoder.inputs{1}.size = net.inputs{1}.size;
encoder.layers{1}.size = net.layers{1}.size;
encoder.layers{1}.transferFcn = net.layers{1}.transferFcn;
encoder.IW{1,1} = net.IW{1,1};
encoder.b{1} = net.b{1};
% Set a training function
encoder.trainFcn = net.trainFcn;
% Set the input
encoderStruct = struct(encoder);
networkStruct = struct(net);
encoderStruct.inputs{1} = networkStruct.inputs{1};
encoder = network(encoderStruct);
% extract features from net
features2 = encoder(X1);
% compare
figure
bar([features1(:,1),features2(:,1)])
If you use stacked autoencoders use encode function.
Here is a good example .
  댓글 수: 2
Chris Tostado
Chris Tostado 2020년 3월 30일
At the end of your post you mention "If you use stacked autoencoders use encode function." However, I'm not quite sure what you mean here. Do you mean if one were to use the "stack" function to combine multiple autoencoders, that instead of using:
% extract features from net
features2 = encoder(X1);
we should use:
% extract features from net
features2 = encode(encoder, X1); ???
The stack function, from my understanding creates a network type object in which case, the encode function no longer works. Can you please advise? Thanks!
Giuseppe Bisazza
Giuseppe Bisazza 2021년 10월 1일
I need to extract the decoder part instead of the encoder from a trained autoencoder. Could you please help me?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by