Architecture of convolutional autoencoders in Matlab 2019b

42 views (last 30 days)
Hello all,
I am very interested in training convolutional autoencoders in MATLAB 2019b.
I have found the instruction trainAutoencoder, but it does not allow to specify the convolutional layers architecture.
I want to design my autoencoder using Deep Network Designer tool, and then train it just as it is done with CNNs, FasterRCNN algorithms, etc, using my image dataset.
Is this possible? Is there any code oxample out there to do so?
Thank you all in advance,
Best,
Alberto

Accepted Answer

Mahesh Taparia
Mahesh Taparia on 23 Mar 2020
Hi
You can define custom architecture of auoencoder using deep learning layers. You can refer to this documentation for the list of deep learning layers supported in MATLAB. For example, the autoencoder network can be defined as:
layers=[
imageInputLayer(size,"Name","imageinput",'Normalization','none') %size is the size of input
fullyConnectedLayer(9*R,"Name","fc_1") %R can be any number/ factor
leakyReluLayer(0.01,"Name","leakyrelu_1")
fullyConnectedLayer(6*R,"Name","fc_2")
leakyReluLayer(0.01,"Name","leakyrelu_3")
fullyConnectedLayer(3*R,"Name","fc_3")
leakyReluLayer(0.01,"Name","leakyrelu_4")
fullyConnectedLayer(R,"Name","fc_4")
batchNormalizationLayer("Name","batchnorm")
reluLayer('Name','relu1')
dropoutLayer('Name','drop')
fullyConnectedLayer(3*R,"Name","fc_4")
leakyReluLayer(0.01,"Name","leakyrelu_5")
fullyConnectedLayer(6*R,"Name","fc_4")
leakyReluLayer(0.01,"Name","leakyrelu_6")
fullyConnectedLayer(9*R,"Name","fc_4")
leakyReluLayer(0.01,"Name","leakyrelu_7")
fullyConnectedLayer(size,"Name","fc_5")
leakyReluLayer(0.01,"Name","leakyrelu_8")
regressionLayer("Name","regressionoutput")];
You can use 2D / 3D conv layer/ any other layer as per your architecture. After defining the network, you can train the model. For reference you can check this documentation for that.
For custom loss function, you can check this documentation.
Hope it will help!
  3 Comments
Mahesh Taparia
Mahesh Taparia on 17 Oct 2020
Hi
You can replace the fully connected layer with convolution layer in the above code, then it will be a convolutional autoencoder. You can refer to this documentation of convolution layer for more details. You can change the layers as per your application.
Jian Wang
Jian Wang on 29 May 2021
Hi, Mahesh Taparia. Thank you for your answer. I want to know how can I train the autoencoder in Matlab? I use the following code:
net = trainNetwork(X, X, AE_Layers, AE_options);
X is a array with 13457-by-7, i.e. 7 variables.
But it seems wrong when I get the reconstructed X by:
XReconstructed = predict(net, X);
XReconstructed is full of NANs. Whether the code is wrong? Thank you.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!