MATLAB: How to train an autoencoder without trainAutoencoder function

Deep Learning Toolboxfully connected networkmachine learningMATLABneural networktrain network

I what train an autoencoder without trainAutoencoder function.
Then I got some problems.
The learning of the network stopped at a certain value, and the output image was different from the input.
Despite the nodes of the hidden layer being larger than the input size.
I must have overlooked, but I can not consider it.
The code and output.
rng('default')
% Load the training data into memory
[xTrainImages,tTrain] = digitTrainCellArrayData;
N = length(xTrainImages);
hiddenSize = 1000;
%%cell to array(alter cell into vector)
T = zeros(numel(xTrainImages),28*28);
for i = 1:numel(xTrainImages)
T(i,:) = xTrainImages{i}(:)';
end
X = T';
T = T';
%%neural networks setting and training
net = fitnet(hiddenSize);
net.trainFcn = 'trainscg';
net = configure(net,X,T);
net = train(net,X,T);
%%denoising images
h1 = figure;
h2 = figure;
figure(h1)
for i = 1:20
subplot(4,5,i);
imshow(xTrainImages{i})
end
figure(h2);
for i = 1:20
subplot(4,5,i);
imshow(reshape(net(xTrainImages{i}(:)),28,28));
end

Best Answer

I solved it after sparse learning.