File Exchange

image thumbnail

Deep Learning Tutorial Series

Download code and watch video series to learn and implement deep learning techniques


Updated 05 Dec 2017

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The code provides hands-on examples to implement convolutional neural networks (CNNs) for object recognition. The three demos have associated instructional videos that will allow for a complete tutorial experience to understand and implement deep learning techniques.
The demos include:
- Training a neural network from scratch
- Using a pre-trained model (transfer learning)
- Using a neural network as a feature extractor
The corresponding videos for the demos are located here:
The use of a GPU and Parallel Computing Toolbox™ is recommended when running the examples. Demo 3 requires Statistics and Machine Learning Toolbox™ in addition to the required products below.

Comments and Ratings (40)

I get this error: Undefined function or variable 'saveCIFAR10AsFolderOfImages'.
Please help

>> DownloadCIFAR10
Downloading 174MB CIFAR-10 dataset...
Error using websave (line 106)
The error "Error copying data." occurred while communicating with URL
Error in DownloadCIFAR10 (line 13)
how can i correct this error
Help me

Adib Rezaei

Error: File: saveCIFAR10AsFolderOfImages.m Line: 55 Column: 1
"data" previously appeared to be used as a function or command, conflicting with its use here as the
name of a variable.
A possible cause of this error is that you forgot to initialize the variable, or you have initialized
it implicitly using load or eval.

please help

Got it.

trainingFeatures = activations(convnet, trainingSet, featureLayer); to trainingFeatures = activations(convnet, trainingSet, featureLayer ,'OutputAs','rows');


testFeatures = activations(convnet, testSet, featureLayer); to testFeatures = activations(convnet, testSet, featureLayer ,'OutputAs','rows');

I get the same error as Vasilis mentions below... Why does Matlab publish a tutorial that doesn't work? It's so unbelievably frustrating.. Noone should have to PAY MONEY for a product that doesn't work

I get this error on line 17: classifier = fitcnb(trainingFeatures, trainingSet.Labels);

error using classreg.learning.FullClassificationRegressionModel.prepareDataCR (line 192) X must be a numeric matrix.

Do you have any idea what this is? I check Z and it is a 1x1x4096x200 matrix with numbers (single array)

Liying Chou

Gayathri g


Xin Gao

what should i do if i don't have @readFunctionTrain

Matlab Mebin

Any support for deep learning pls contact


call -+91 9994444414

Code for gpu doesnt work on cpu. Which command is the replacement for gpuArray for a CPU?

Thank you for such a great video, but I have a question.
Can we use 16 layers of AlexNet instead of using all layers it has?
And if yes, how can we do that? Can you help me please?

An Gie Lo

How can I change the codes so that it downloads CIFAR-100 from the url and prepare .mat files as image folder like how it did for CIFAR-10? I had tried on my own by manipulating the codes for the image folder saving part for CIFAR-100 related .mat file, it couldn't work. Please help.

ann antony



>> DownloadCIFAR10
Downloading 174MB CIFAR-10 dataset...
Error using websave (line 106)
The error "Error copying data." occurred while communicating with URL

Error in DownloadCIFAR10 (line 13)

how can i correct this error

John Hu

Problem solved! -"Out of Memory on device...."
The trainNetWork() function contains opts parameter.
I depressed the 'MiniBatchSize' of opts from 128 to 64.
And also it took more time.
Good Course!

John Hu

When i ran the file Demo_TransferLearning.mlx at trainNetwork() function, it crashed, given the information "Out of Memory on device....".
I tried gpuDevice(1) statement, but it occurred again.
My GPU is GeForce GTX 965M with 4GB.
Should i config some parameters in Matlab?

Parul Sahi

In the program demo_TrainingFromScratch:
fc1 = fullyConnectedLayer(64,'BiasLearnRateFactor',2);
In the above code how are 64 neurons chosen in the fully connected layer.
fc1.Weights = single(randn([64 576])*0.1);
Also what does 576 indicate in the above code.


alaa basel

confMat = confusionmat(imds_test.Labels, labels);
confMat = confMat./sum(confMat,2);
when i am runnig this part of code i got this massege(error using ./ matrix dimensions must agree ) what should i change to make it right

very helpful. I hope there will be something on regression in the future.

Is there any specific requirement for minimum version of MATLAB ? I am having errors saying undefined function, may be my MATLAB version don't has that function implemented.

Hasan Erdem

Hasan Erdem

I think, you need to change convnet to net Demo_FeatureExtraction.

Kyle Cheng

thanks for your video. I have one question. For running this simulation, DO I need to have GPU on my computer?


thanks for so excellent video. I have a question for the transfer learning demo. In Matlab, all layers except the last three(any other number) are extracted from the pretrained network, and the last three layers are replaced by new one. There are a few finetune ways, such as finetune the whole network, finetune the last classifier layer, or finetune from any specificed layer. So, I wonder what is the finetune ways in Matlab. finetune the whole network or finetune the last classifier layer? the trainNetwork function implements the retrain( finetune the whole network) ?

Hui Cui

I am sorry, THIS is the error I am getting:
Undefined function or variable 'convnet'.

Eleanor Li


Leow Bin



anggi nego


minor bug fix in third file, "Demo_FeatureExtraction.mlx" :
on line 1 & 2, variable 'net' changed to 'convnet'

+ Fixed typo in code.

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux