File Exchange

image thumbnail

Code Examples from Deep Learning Ebook

version (1.34 MB) by Johanna Pingel
Follow along with the code examples from the "Practical Deep Learning Examples with MATLAB" ebook


Updated 09 May 2018

View License

Learn three approaches to training a deep learning neural network:
1. training from scratch
2. transfer learning
3. semantic segmentation
This submission, along with the corresponding ebook, offers a hands-on approach to deep learning.

Cite As

Johanna Pingel (2021). Code Examples from Deep Learning Ebook (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (21)

志滔 张


Johanna - I have Nvidia Quadro P620 version 443.32
The different example you pointed out does not work

Johanna Pingel

Davide - Which GPU do you have? A few options:
Check your drivers that they are the most up to date.
Change the mini batch size (though the example already has it set low at 4).
Try a different example and see if the error is the same or different:


With R2020a when running Demo3 Semantic Segmentation I got this error:
Error using trainNetwork (line 170)
Out of memory.

Error in DeepLearning_For_SemanticSegmentation_code (line 362)
[net, info] = trainNetwork(datasource,lgraph,options);

Caused by:
Out of memory.

More information

This does not make sense I have a new machine with 32Gb of SRAMs.

Please advice

Johanna Pingel

@Davide - in the file validatePerformance.m Remove lines 7 & 12-14. I'm hoping this clears the error.

In general, this file is to display simple accuracy and a few other metrics after the network is trained. There are other examples of this in documentation which are a better option, in my opinion!


With R2020a when running Demo2 Transfer Learning I get this error:
Not enough input arguments.

Error in validatePerformance (line 7)
if doTest

Error in TransferLearningDemo (line 291)
accuracy_bayesopt = validatePerformance(net,testDS) %#ok display

Could you please fix it?

qiu tao

Maxwell Hogan

just ctrl+f found Johanna's comment


Ebook Formatting Help

Great one to start with on it..

Seunghoon Lee

Thanks a lot!

Adam Lysiak

Got it, I downloaded individual files before. Thanks a lot!

Johanna Pingel

@Adam - the MNISTModel is a .mat file included in the download of the files. It should be under Demo1_MNIST/MNISTModel.mat

Adam Lysiak

Hey, where can I find MNISTModel file (line 22)?

Johanna Pingel

@Venkat - you can remove those lines of code, and the function should run properly without them. This was an old artifact that can be removed. Let me know if you have any trouble.

Johanna Pingel

@Fajar: You are going to run into errors using this code in 2014a. The error is most likely because the function webread() was not introduced until 2014b. You can download the files manually using the link rather than using webread, but you will run into other challenges with the version 2014a, since our deep learning support came out in R2017a

Venkat Sastry

Thank you for sharing the code for these examples. In the function prepareData.m, a couple of lines have been commented out. These are:
% img = readMNISTImage(imgDataTrain, 3);
% figure, imshow(img);

I wasn't able to locate the function readMNISTImage readily. Am I missing anything obvious? Very grateful if you could pint me in the right direction.
Venkat. v.v.s.s.sastry[AT]

Fajar Budi C

i have this error.

>> MNIST_Classification_Demo
Preparing MNIST data...
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in prepareData (line 42)
magicNum = fread(fid, 1, 'uint32');

Error in MNIST_Classification_Demo (line 11)
[imgDataTrain, labelsTrain, imgDataTest, labelsTest] = prepareData;

i use R2014a

JinHyun Park

vigneash pandiyan

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

Community Treasure Hunt

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

Start Hunting!