Use Deep Network Designer to Setup an Autoencoder
Show older comments
I'm trying out MATLAB's deep network designer and having trouble setting up a simple autoencoder for MNIST images. Can anyone provide an example of how to read in MNIST images and feed them into a simple autoencoder so that their label's are just the images themselves? I just want a simple MSE reconstruction, and the ability to compare images with their reconstruction.
This is what I have tried:
unzip("DigitsData.zip")
%data from matlab example -->
%CreateImageClassificationNetworkUsingDeepNetworkDesignerExample
imds = imageDatastore("DigitsData", ...
IncludeSubfolders=true, ...
LabelSource="foldernames");
imds.ReadFcn = @(x) imresize(imread(x), [28 28]);
autoencoderData = transform(imds, @(data) ({data, data}));
options = trainingOptions('adam', ...
'Plots', 'training-progress', ...
'Metrics', 'rmse', ...
'MiniBatchSize', 200,...
'MaxEpochs',4,...
'TargetDataFormats', 'SSCB');
net = trainnet(autoencoderData,net_1,"mse",options);
Where net_1 is desinged using the designer with ImageInput of 28x28x1, followed by a fully connected (output 64), relu, fully connected (784), relu, then sigmoid and finally a resize2dLayer (for output size) set to 28x28.
I get the error: Error using trainnet - Size of predictions and targets must match.
I'm not sure if the error is with the layer sizes or the input autoencoderData (my attempt at making image labels be the images themselves). Any help would be appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!