How can I train a regression layer using the autoencoder approach

Technical Source
2 min readJun 28, 2021

--

I am trying to adapt example provided here

https://www.mathworks.com/help/releases/R2017a/nnet/examples/training-a-deep-neural-network-for-digit-classification.html

Except that I want to replace

softnet = trainSoftmaxLayer(feat2,tTrain,'MaxEpochs',400);

With something similar to this

options = trainingOptions('sgdm','MaxEpochs',20,...'InitialLearnRate',0.0001);routputlayer = regressionLayer('Name','routput');trainedROL = trainNetwork(feat2,yTrain,routputlayer,options);

However, I receive the following error:

Error using trainNetwork>iAssertXAndYHaveSameNumberOfObservations (line 604)

X and Y must have the same number of observations.

Error in trainNetwork>iParseInput (line 336)

iAssertXAndYHaveSameNumberOfObservations( X, Y );

Error in trainNetwork (line 68)

[layers, opts, X, Y] = iParseInput(varargin{:});

Error in test (line 176)

trainedROL = trainNetwork(feat2,tTrain,routputlayer,options);

How can I modify the algorithm to do regression rather than classification?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Regression is not natively supported within the autoencoder framework. There is no equivalent to the trainSoftmaxLayer function which accepts a feature input matrix of dimensions featureSize-by-numObs.

The trainNetwork function in MATLAB R2017a is designed for image learning problems — i.e. when the input data has dimensions height-by-width-by-channels-by-numObs. So the autoencoder output is not natively supported by trainNetwork.

However, you can manipulate the dimensions of the autoencoded features to make it compatible with the regressionLayer in trainNetwork. See below an example script which demonstrates this, using the feat2 output from the second autoencoder from the example in “Train Stacked Autoencoders for Image Classification”. Again, keep in mind this is not quite the intended workflow for either autoencoders or SeriesNetworks from trainNetwork.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet