www.gusucode.com > nnet 案例源码 matlab代码程序 > nnet/ReconstructHandwrittenDigitImagesExample.m
%% Reconstruct Handwritten Digit Images %% % Load the training data. X = digitTrainCellArrayData; %% % The training data is a 1-by-5000 cell array, where each cell containing % a 28-by-28 matrix representing a synthetic image of a handwritten digit. %% % Train an autoencoder with a hidden layer containing 25 neurons. hiddenSize = 25; autoenc = trainAutoencoder(X,hiddenSize,... 'L2WeightRegularization',0.004,... 'SparsityRegularization',4,... 'SparsityProportion',0.15); %% % Load the test data. x = digitTestCellArrayData; %% % The test data is a 1-by-5000 cell array, with each cell containing a 28-by-28 % matrix representing a synthetic image of a handwritten digit. %% % Reconstruct the test image data using the trained autoencoder, |autoenc|. xReconstructed = predict(autoenc,x); %% % View the actual test data. figure; for i = 1:20 subplot(4,5,i); imshow(X{i}); end %% % View the reconstructed test data. figure; for i = 1:20 subplot(4,5,i); imshow(xReconstructed{i}); end