4.4 Neural Networks Intuition | Example Recognizing Images--[Machine Learning | Andrew Ng]
 In the last video, you saw how a neural network works in a demand prediction example. Let's take a look at how you can apply a similar type of idea to a computer vision application. Let's dive in. If you're building a face recognition application, you might want to train, say, a neural network that takes this input to picture like this and outputs the identity of the person in the picture. This image is a thousand by a thousand pixels and so its representation in the computer is actually as a thousand by a thousand grid or also called a thousand by a thousand matrix of pixel intensity values. In this example, my pixel intensity values or pixel brightness values goes from 0 to 255 and so 197 here would be the brightness of the pixel in the very upper left of the image, 185 is the brightness of the pixel, one pixel over and so on, down to 214 would be the lower right corner of this image. If you were to take these pixel intensity values and unroll them into a vector, you end up with a list or a vector of a million pixel intensity values, one million because a thousand by a thousand squared gives you a million numbers. The face recognition problem is, can you train a neural network that takes this input, a feature vector with a million pixel brightness values and outputs the identity of the person in the picture? This is how you might build a neural network to carry out this task. The input image X is fed to this layer of neurons, this is the first hidden layer, which then extracts some features and the output of this first hidden layer is fed to a second hidden layer and that output is fed to a third hidden layer and then finally to the output layer which then estimates, say, the probability of this being a particular person. One interesting thing would be if you look at a neural network that's been trained on a lot of images of faces and to try to visualize what are these hidden layers trying to compute. It turns out that when you train a system like this on a lot of pictures of faces and you peer at the different neurons in the hidden layers to figure what they may be computing, this is what you might find. In the first hidden layer, you might find one neuron that is looking for a little vertical line or a vertical edge like that and a second neuron looking for a oriented line or oriented edge like that and a third neuron looking for a line at that orientation and so on. In the earliest layers of a neural network, you might find that the neurons are looking for very short lines or very short edges in the image. If you look at the next hidden layer, you find that these neurons might learn to group together lots of little short lines, little short edge segments in order to look for parts of faces. For example, each of these little square boxes is a visualization of what that neuron is trying to detect. This first neuron looks like it's trying to detect the presence or absence of an eye in a certain position of the image and the second neuron looks like it's trying to detect the horn of a nose and maybe this neuron over here is trying to detect the bottom of a nose. And then as you look at the next hidden layer, in this example, the neural network is aggregating different parts of faces to then try to detect presence or absence of larger, coarser face shapes. And then finally, detecting how much the face corresponds to different face shapes creates a rich set of features that then helps the upper layer try to determine the identity of the person pictured. And a remarkable thing about the neural network is it can learn these feature detectors at the different hidden layers all by itself. In this example, no one ever told it to look for short little edges in the first layer and eyes and noses and face parts in the second layer and then more complete face shapes at the third layer. The neural network is able to figure out these things all by itself from data. Just one note, in this visualization, the neurons in the first hidden layer are shown looking at relatively small windows to look for these edges. And then the second hidden layer is looking at a bigger window and the third hidden layer is looking at an even bigger window. So these little neurons visualizations actually correspond to differently sized regions in the image. Just for fun, let's see what happens if you were to train this neural network on a different data set, say on lots of pictures of cars pictured on the side. The same learning algorithm, if it's asked to detect cars, will then learn edges in the first layer, so pretty similar, but then they'll learn to detect parts of cars in the second hidden layer and then more complete car shapes in the third hidden layer. So just by feeding it different data, the neural network automatically learns to detect very different features so as to try to make the predictions of car detection or person recognition or whatever is a particular given task that it's trained on. So that's how a neural network works for a computer vision application. And in fact, later this week, you see how you can build a neural network yourself and apply it to a handwritten digit recognition application. So far, we've been going over the description of intuitions of neural networks to give you a feel for how they work. In the next video, let's look more deeply into the concrete mathematics and the concrete implementational details of how you actually build one or more layers of a neural network and therefore how you can implement one of these things yourself. Let's go on to the next video.
[{"start": 0.0, "end": 6.92, "text": " In the last video, you saw how a neural network works in a demand prediction example."}, {"start": 6.92, "end": 12.56, "text": " Let's take a look at how you can apply a similar type of idea to a computer vision application."}, {"start": 12.56, "end": 13.56, "text": " Let's dive in."}, {"start": 13.56, "end": 18.56, "text": " If you're building a face recognition application, you might want to train, say, a neural network"}, {"start": 18.56, "end": 23.88, "text": " that takes this input to picture like this and outputs the identity of the person in"}, {"start": 23.88, "end": 25.6, "text": " the picture."}, {"start": 25.6, "end": 32.760000000000005, "text": " This image is a thousand by a thousand pixels and so its representation in the computer"}, {"start": 32.760000000000005, "end": 39.72, "text": " is actually as a thousand by a thousand grid or also called a thousand by a thousand matrix"}, {"start": 39.72, "end": 42.88, "text": " of pixel intensity values."}, {"start": 42.88, "end": 48.36, "text": " In this example, my pixel intensity values or pixel brightness values goes from 0 to"}, {"start": 48.36, "end": 55.96, "text": " 255 and so 197 here would be the brightness of the pixel in the very upper left of the"}, {"start": 55.96, "end": 63.480000000000004, "text": " image, 185 is the brightness of the pixel, one pixel over and so on, down to 214 would"}, {"start": 63.480000000000004, "end": 67.28, "text": " be the lower right corner of this image."}, {"start": 67.28, "end": 73.72, "text": " If you were to take these pixel intensity values and unroll them into a vector, you"}, {"start": 73.72, "end": 81.24, "text": " end up with a list or a vector of a million pixel intensity values, one million because"}, {"start": 81.24, "end": 85.6, "text": " a thousand by a thousand squared gives you a million numbers."}, {"start": 85.6, "end": 91.84, "text": " The face recognition problem is, can you train a neural network that takes this input, a"}, {"start": 91.84, "end": 98.36, "text": " feature vector with a million pixel brightness values and outputs the identity of the person"}, {"start": 98.36, "end": 100.36, "text": " in the picture?"}, {"start": 100.36, "end": 105.8, "text": " This is how you might build a neural network to carry out this task."}, {"start": 105.8, "end": 112.76, "text": " The input image X is fed to this layer of neurons, this is the first hidden layer, which"}, {"start": 112.76, "end": 119.08, "text": " then extracts some features and the output of this first hidden layer is fed to a second"}, {"start": 119.08, "end": 125.03999999999999, "text": " hidden layer and that output is fed to a third hidden layer and then finally to the output"}, {"start": 125.04, "end": 131.56, "text": " layer which then estimates, say, the probability of this being a particular person."}, {"start": 131.56, "end": 136.68, "text": " One interesting thing would be if you look at a neural network that's been trained on"}, {"start": 136.68, "end": 143.64000000000001, "text": " a lot of images of faces and to try to visualize what are these hidden layers trying to compute."}, {"start": 143.64000000000001, "end": 149.0, "text": " It turns out that when you train a system like this on a lot of pictures of faces and"}, {"start": 149.0, "end": 155.56, "text": " you peer at the different neurons in the hidden layers to figure what they may be computing,"}, {"start": 155.56, "end": 157.64, "text": " this is what you might find."}, {"start": 157.64, "end": 164.12, "text": " In the first hidden layer, you might find one neuron that is looking for a little vertical"}, {"start": 164.12, "end": 171.4, "text": " line or a vertical edge like that and a second neuron looking for a oriented line or oriented"}, {"start": 171.4, "end": 178.16, "text": " edge like that and a third neuron looking for a line at that orientation and so on."}, {"start": 178.16, "end": 182.44, "text": " In the earliest layers of a neural network, you might find that the neurons are looking"}, {"start": 182.44, "end": 188.35999999999999, "text": " for very short lines or very short edges in the image."}, {"start": 188.35999999999999, "end": 195.92, "text": " If you look at the next hidden layer, you find that these neurons might learn to group"}, {"start": 195.92, "end": 201.96, "text": " together lots of little short lines, little short edge segments in order to look for parts"}, {"start": 201.96, "end": 202.96, "text": " of faces."}, {"start": 202.96, "end": 209.12, "text": " For example, each of these little square boxes is a visualization of what that neuron is"}, {"start": 209.12, "end": 211.12, "text": " trying to detect."}, {"start": 211.12, "end": 215.84, "text": " This first neuron looks like it's trying to detect the presence or absence of an eye in"}, {"start": 215.84, "end": 222.8, "text": " a certain position of the image and the second neuron looks like it's trying to detect the"}, {"start": 222.8, "end": 231.44, "text": " horn of a nose and maybe this neuron over here is trying to detect the bottom of a nose."}, {"start": 231.44, "end": 237.0, "text": " And then as you look at the next hidden layer, in this example, the neural network is aggregating"}, {"start": 237.0, "end": 244.07999999999998, "text": " different parts of faces to then try to detect presence or absence of larger, coarser face"}, {"start": 244.07999999999998, "end": 245.07999999999998, "text": " shapes."}, {"start": 245.07999999999998, "end": 252.04, "text": " And then finally, detecting how much the face corresponds to different face shapes creates"}, {"start": 252.04, "end": 257.65999999999997, "text": " a rich set of features that then helps the upper layer try to determine the identity"}, {"start": 257.65999999999997, "end": 260.04, "text": " of the person pictured."}, {"start": 260.04, "end": 264.40000000000003, "text": " And a remarkable thing about the neural network is it can learn these feature detectors at"}, {"start": 264.40000000000003, "end": 267.84000000000003, "text": " the different hidden layers all by itself."}, {"start": 267.84000000000003, "end": 272.76000000000005, "text": " In this example, no one ever told it to look for short little edges in the first layer"}, {"start": 272.76000000000005, "end": 277.40000000000003, "text": " and eyes and noses and face parts in the second layer and then more complete face shapes at"}, {"start": 277.40000000000003, "end": 278.40000000000003, "text": " the third layer."}, {"start": 278.40000000000003, "end": 283.32000000000005, "text": " The neural network is able to figure out these things all by itself from data."}, {"start": 283.32000000000005, "end": 288.8, "text": " Just one note, in this visualization, the neurons in the first hidden layer are shown"}, {"start": 288.8, "end": 293.8, "text": " looking at relatively small windows to look for these edges."}, {"start": 293.8, "end": 297.84000000000003, "text": " And then the second hidden layer is looking at a bigger window and the third hidden layer"}, {"start": 297.84000000000003, "end": 300.56, "text": " is looking at an even bigger window."}, {"start": 300.56, "end": 306.08000000000004, "text": " So these little neurons visualizations actually correspond to differently sized regions in"}, {"start": 306.08000000000004, "end": 307.68, "text": " the image."}, {"start": 307.68, "end": 312.96000000000004, "text": " Just for fun, let's see what happens if you were to train this neural network on a different"}, {"start": 312.96, "end": 319.12, "text": " data set, say on lots of pictures of cars pictured on the side."}, {"start": 319.12, "end": 326.96, "text": " The same learning algorithm, if it's asked to detect cars, will then learn edges in the"}, {"start": 326.96, "end": 332.64, "text": " first layer, so pretty similar, but then they'll learn to detect parts of cars in the second"}, {"start": 332.64, "end": 337.88, "text": " hidden layer and then more complete car shapes in the third hidden layer."}, {"start": 337.88, "end": 344.6, "text": " So just by feeding it different data, the neural network automatically learns to detect"}, {"start": 344.6, "end": 352.86, "text": " very different features so as to try to make the predictions of car detection or person"}, {"start": 352.86, "end": 357.88, "text": " recognition or whatever is a particular given task that it's trained on."}, {"start": 357.88, "end": 361.0, "text": " So that's how a neural network works for a computer vision application."}, {"start": 361.0, "end": 366.0, "text": " And in fact, later this week, you see how you can build a neural network yourself and"}, {"start": 366.0, "end": 370.9, "text": " apply it to a handwritten digit recognition application."}, {"start": 370.9, "end": 375.8, "text": " So far, we've been going over the description of intuitions of neural networks to give you"}, {"start": 375.8, "end": 378.2, "text": " a feel for how they work."}, {"start": 378.2, "end": 383.56, "text": " In the next video, let's look more deeply into the concrete mathematics and the concrete"}, {"start": 383.56, "end": 389.8, "text": " implementational details of how you actually build one or more layers of a neural network"}, {"start": 389.8, "end": 393.24, "text": " and therefore how you can implement one of these things yourself."}, {"start": 393.24, "end": 396.32, "text": " Let's go on to the next video."}]