File Exchange

image thumbnail

Deep Learning in 11 Lines of MATLAB Code

Use MATLAB®, a simple webcam, and a deep neural network to identify objects in your surroundings.

458 Downloads

Updated

View License

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

MATLAB code associated with the demo in 'Deep Learning in 11 Lines of MATLAB Code' video.
https://www.mathworks.com/videos/deep-learning-in-11-lines-of-matlab-code-1481229977318.html
This demo uses AlexNet, a pretrained deep convolutional neural network (CNN or ConvNet) that has been trained on over a million images.
The example has two parts: setting up the camera and performing object recognition. The first part shows how to use the webcam command to acquire images from the camera. Using the drawnow command, MATLAB is able to continuously update and display images taken by the camera.
You can download the webcam support package here:
https://www.mathworks.com/matlabcentral/fileexchange/45182-matlab-support-package-for-usb-webcams

The second part illustrates how to download a pretrained deep neural network called AlexNet and use MATLAB to continuously process the camera images. AlexNet takes the image as input and provides a label for the object in the image. You can experiment with objects in your surroundings to see how accurate AlexNet is.

You can download the AlexNet support package here:
https://www.mathworks.com/matlabcentral/fileexchange/59133-neural-network-toolbox-tm--model-for-alexnet-network

Comments and Ratings (13)

Muzee

Muzee (view profile)

hi, there is an error when i run the codes: CUDA driver version is insufficient for CUDA runtime version. And i want to know what kind of CUDA does Alexnet need?

renjith ms

I could ony classify key board
when mouse was shone it was being classified as something else

tanu gupta

cem sincap

I am getting the that error while starting the TransferLearningVideo.m. these errors ;

>> TransferLearningVideo

Error using trainNetwork (line 64)
The output size (5) of the last layer doesn't match the number of classes (1).

Error in TransferLearningVideo (line 17)
myNet = trainNetwork(trainingImages, layers, opts);

my

my (view profile)

Thanks, Nice explanation!, please consider next time using less toolboxes that we need not to purchase.

Danh Lam

Undefined function or variable 'alexnet'.

Error in DeepLearning_in_11_Lines (line 3)
nnet = alexnet;

Tommy

Tommy (view profile)

I tried running this example, but it does not work. It is trying to use classify for statistics toolbox and not net classify - can you please help me solve this issue?

I have nnet installed as well.

Error ----
> In alexnet (line 46)
In MyFirstDeepLearningTest (line 4)
Error using classify (line 122)
Requires at least three arguments.

Error in MyFirstDeepLearningTest (line 10)
label = classify(nnet, picture); % Classify the picture

Hans Scharler

jiro

jiro (view profile)

@Anthony, this submission requires the Neural Network Toolbox. You may not have that toolbox installed.

Anthony Slata

I tried to run this code and it returns an error saying that "classify requires 3 parameters". What is the 3rd parameter?

Updates

1.0

Updated image.

1.0

Added link to demo video.

MATLAB Release
MATLAB 9.1 (R2016b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today

WebcamObjectClassification/