Ebook

What Is Deep Learning?

Deep learning is a type of machine learning in which a model learns to perform classification tasks directly from images, text, or sound. Deep learning is usually implemented using a neural network architecture. The term “deep” refers to the number of layers in the network—the more layers, the deeper the network. Traditional neural networks contain only 2 or 3 layers, while deep networks can have hundreds.

Deep Learning in Action

Deep learning is especially well-suited to identification applications such as face recognition, text translation, voice recognition, and advanced driver assistance systems, including, lane classification and traffic sign recognition.

  • A self-driving vehicle slows down as it approaches a pedestrian crosswalk.
  • An ATM rejects a counterfeit bank note.
  • A smartphone app gives an instant translation of a foreign street sign.

What Makes Deep Learning Possible

Three major advancements in technology have made deep learning much more achievable. Advance the slideshow below to explore them.

  Deep Neural Networks Basics   

Inside a Deep Neural Network

A deep neural network combines multiple nonlinear processing layers, using simple elements operating in parallel and inspired by biological nervous systems. It consists of an input layer, several hidden layers, and an output layer. The layers are interconnected via nodes, or neurons, with each hidden layer using the output of the previous layer as its input.

How a Deep Neural Network Learns

Let’s say we have a set of images where each image contains one of four different categories of objects, and we want the deep learning network to automatically recognize which object is in each image. We label the images in order to have training data for the network.

Using this training data, the network can then start to understand the object’s specific features and associate them with the corresponding category.

Each layer in the network takes in data from the previous layer, transforms it, and passes it on. The network increases the complexity and detail of what it is learning from layer to layer.

Notice that the network learns directly from the data—we have no influence over what features are being learned.

Learn how to use transfer learning in MATLAB to re-train deep learning networks created by experts for your own data or task.

Convolutional Neural Networks

A deep neural network combines multiple nonlinear processing layers, using simple elements operating in parallel and inspired by biological nervous systems. It consists of an input layer, several hidden layers, and an output layer. The layers are interconnected via nodes, or neurons, with each hidden layer using the output of the previous layer as its input.

A convolutional neural network (CNN, or ConvNet) is one of the most popular algorithms for deep learning. Like other neural networks, a CNN is composed of an input layer, an output layer, and many hidden layers in between.

Feature Detection Layers

These layers perform one of three types of operations on the data: convolution, pooling, or rectified linear unit (ReLU).

Convolution puts the input images through a set of convolutional filters, each of which activates certain features from the images.

Pooling simplifies the output by performing nonlinear downsampling, reducing the number of parameters that the network needs to learn about.

Rectified linear unit (ReLU) allows for faster and more effective training by mapping negative values to zero and maintaining positive values.

These three operations are repeated over tens or hundreds of layers, with each layer learning to detect different features.

Classification Layers

After feature detection, the architecture of a CNN shifts to classification.

The next-to-last layer is a fully connected layer (FC) that outputs a vector of K dimensions where K is the number of classes that the network will be able to predict.  This vector contains the probabilities for each class of any image being classified.

The final layer of the CNN architecture uses a softmax function to provide the classification output.

Getting Started with Deep Learning

If you’re new to deep learning, a quick and easy way to get started is to use an existing network, such as GoogLeNet, a CNN trained on more than a million images. GoogLeNet is most commonly used for image classification. It can classify images into 1000 different categories, including keyboards, computer mice, pencils, and other office equipment, as well as various breeds of dogs, cats, horses, and other animals.

An Example Using GoogLeNet

You can use GoogLeNet to classify objects in any image. In this example, we’ll use it to classify objects in an image from a webcam installed on a desktop.  In addition to MATLAB®, we’ll be using the following:

After loading GoogLeNet we connect to the webcam and capture a live image.

camera = webcam;           % Connect to the camera
nnet = googlenet;          % Load the neural net
picture = camera.snapshot; % Take a picture

Next, we resize the image to 224x224 pixels, the size required by GoogLeNet.

picture = imresize(picture,[224,224]); % Resize the picture

GoogLeNet can now classify our image.

label = classify(nnet, picture); % Classify the picture
image(picture);                  % Show the picture
title(char(label));              % Show the label

Retraining an Existing Network

To use GoogLeNet for objects not trained in the original network, we can retrain it through transfer learning. Transfer learning is an approach that applies knowledge of one type of problem to a different but related problem. In this case, we simply trim off the last three layers of the network and retrain them with our own images.

Computational Resources for Deep Learning

Training a deep learning model can take hours, days, or weeks, depending on the size of the data and the amount of processing power you have available. Selecting a computational resource is a critical consideration when you set up your workflow.

Currently, there are three popular computation options: CPU-based, GPU-based, and cloud-based.

CPU-based computation is the simplest and most readily available option. The example described in the previous section works on a CPU, but we recommend using CPU-based computation only for simple examples using a pretrained network.

Using a GPU reduces network training time from days to hours. You can use a GPU in MATLAB without doing any additional programming. We recommend an NVIDIA® 3.0 compute-capable GPU. Multiple GPUs can speed up processing even more.

Cloud-based GPU computation means that you don’t have to buy and set up the hardware yourself. The MATLAB code you write for using a local GPU can be extended to use cloud resources with just a few settings changes.