File Exchange

image thumbnail

Deep Learning for Computer Vision Demo Code

version (5.18 KB) by Avi Nehemiah
Deep learning to recognize objects using convolution neural networks(CNN's).


Updated 01 Sep 2016

View License

Use deep learning to:
- Recognize objects using a pre-trained model
- Perform transfer learning to discriminate between two classes using a pre-trained 1000 class network

Cite As

Avi Nehemiah (2020). Deep Learning for Computer Vision Demo Code (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Ali Abed

how could I obtain a cat and dog images?

angel lerma

Greetings from Mexico, excellent webinar and thanks for sharing.

I have an error and I do not know how to solve it, could you help me by giving me an orientation?

The error is in the following lines:
featureLayer = 'fc7';
trainingFeatures = activations (convnet, trainingSet, featureLayer, ...
'MiniBatchSize', 32, 'OutputAs', 'columns');

And what it marks is the following:
Error using / read (line 74)
Error using ReadFcn @ (filename) readAndPreprocessImage (filename) function handle for file
C: \ DeepLearning \ data \ Images \ Arterio_arterial \ CAA_1.png.

Undefined function 'readAndPreprocessImage' for input arguments of type 'char'.

Error in PetDetectionRecognitionScript> @ (filename) readAndPreprocessImage (filename)

Error in nnet.internal.cnn.ImageDatastoreMiniBatchDatastore / read (line 31)
[data, info] = ();

Error in nnet.internal.cnn.MiniBatchDatastoreDispatcher / getExampleInfoFromDatastore (line 312)
[data, info] = read (this.Datastore);

Error in nnet.internal.cnn.MiniBatchDatastoreDispatcher (line 118)
[exampleImage, exampleResponse, this.ResponseMetaData] = getExampleInfoFromDatastore (this);

Error in nnet.internal.cnn.DataDispatcherFactory.createDataDispatcher (line 89)
dispatcher = nnet.internal.cnn.MiniBatchDatastoreDispatcher (datasource, miniBatchSize, endOfEpoch, shuffleOption, precision);

Error in SeriesNetwork> iDataDispatcher (line 1152)
dispatcher = nnet.internal.cnn.DataDispatcherFactory.createDataDispatcher (...

Error in SeriesNetwork / activations (line 806)
dispatcher = iDataDispatcher (X, miniBatchSize, precision, ...

Error in PetDetectionRecognitionScript (line 77)
trainingFeatures = activations (convnet, trainingSet, featureLayer, ...
I have Matlab 2018b in Win 10 64 bit ......

Greetings and thanks in advance

Angel Lerma

Alam Noor

@Kimuya Alex, It is the problem of matlab version. Install new version

Kimuya Alex

I am Using R2015b Matlab version. I am getting the erroe: "Undefined function or variable 'helperImportMatConvNet". Is there a way to resolve this please? Or is the problem the Matlab Version i am using? Any assistance would be much appreciated pls.

how to find the accuracy for this algorithm

if my data set about lung images which net library i should use as a pre training ?? and i can't understand how - in may case - using only the first 2 layers within my data set

good , but can't


Hi, thanks for the demo.
I have a problem that how to get the 'cat.avi' and 'Hobbes.png'?


for images go to kaggel catvsdog competetion

i am unable to run the shows error


Everything is ok unless when it runs to line 131. It showed that 'Struct contents reference from a non-struct array object.'. How should i sovle it? Thank you!

yankun cao

Hi, I met a problem when running this program. It showed that Undefined function or variable 'helperImportMatConvNet'.How should I solve it?

Florian M

Florian M

dimpy yadav

I have Matlab 2016 and Visual studio 2013. What else is required to run the above program? CUDA 7.5 is neccessary?

you need to create your own images in a directory

So where are the petImages?

the code runs fine up to:
dataFolder = 'C:\DeepLearning\data\PetImages';
categories = {'Cat', 'Dog'};
imds = imageDatastore(fullfile(dataFolder, categories), 'LabelSource', 'foldernames');

Files not found!

Can they be downloaded???

I have a problem with the frame detection box. When i play the video of dog, the frame can not recognize all the body of dog and that just focus on head or eye or leg... so i have problem with precise recognizing. Can you help me to fix this problem?
Best regards

pei liu

how could I obtain cat and dog image?

f l

Avi Nehemiah

Anslem - the dataset we used was something we collected internally at MathWorks. Kaggle has a similar dataset with images of cats and dogs that you can try with the same code.

I have watched the webinar on Mathworks website, Shahank and avi both of you did a great job. The explanation was pellucid. I really enjoy working with the MATLAB because of its clear workflows and the apps which saves us a lot of time and energy. Thanks for making things simple.

Can I just check is the data set for the cats and dogs from ImageNet dataset or are they from your own dataset that you collected in an earlier Matlab webinar? Thanks Anselm Griffin

HK Suh


Updated license

Updated required product list.

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