You've already seen most of the components of object detection.

In this video, let's put all the components

together to form the YOLO object detection algorithm.

First, let's see how you construct your training set.

Suppose you're trying to train an algorithm to detect

three objects: pedestrians, cars, and motorcycles.

And you will need to explicitly have the full background class,

so just the class labels here.

If you're using two anchor boxes,

then the outputs y will be three by three because you are using three by three grid cell,

by two, this is the number of anchors,

by eight because that's the dimension of this.

Eight is actually five which is plus the number of classes.

So five because you have Pc and then the bounding boxes,

that's five, and then C1, C2, C3.

That dimension is equal to the number of classes.

And you can either view this as three by three by two by eight,

or by three by three by sixteen.

So to construct the training set,

you go through each of these nine grid cells and form the appropriate target vector y.

So take this first grid cell,

there's nothing worth detecting in that grid cell.

None of the three classes pedestrian, car and motocycle,

appear in the upper left grid cell and so,

the target y corresponding to that grid cell would be equal to this.

Where Pc for the first anchor box

is zero because there's nothing associated for the first anchor box,

and is also zero for the second anchor box and

so on all of these other values are don't cares.

Now, most of the grid cells have nothing in them,

but for that box over there,

you would have this target vector y.

So assuming that your training set has a bounding box like this for the car,

it's just a little bit wider than it is tall.

And so if your anchor boxes are that,

this is a anchor box one,

this is anchor box two,

then the red box has just slightly higher IoU with anchor box two.

And so the car gets associated with this lower portion of the vector.

So notice then that Pc associate anchor box one is zero.

So you have don't cares all these components.

Then you have this Pc is equal to one,

then you should use these to specify the position of the red bounding box,

and then specify that the correct object is class two.

Right that it is a car.

So you go through this and for each of

your nine grid positions each of your three by three grid positions,

you would come up with a vector like this.

Come up with a 16 dimensional vector.

And so that's why the final output volume is going to be 3 by 3 by 16.

Oh and as usual for simplicity on the slide I've used a 3 by 3 the grid.

In practice it might be more like a 19 by 19 by 16.

Or in fact if you use more anchor boxes,

maybe 19 by 19 by 5 x 8 because five times eight is 40.

So it will be 19 by 19 by 40.

That's if you use five anchor boxes.

So that's training and you train ConvNet that inputs an image,

maybe 100 by 100 by 3,

and your ConvNet would then finally output this output volume in our example,

3 by 3 by 16 or 3 by 3 by 2 by 8.

Next, let's look at how your algorithm can make predictions.

Given an image, your neural network will output this by 3 by 3 by 2 by 8 volume,

where for each of the nine grid cells you get a vector like that.

So for the grid cell here on the upper left,

if there's no object there,

hopefully, your neural network will output zero here,

and zero here, and it will output some other values.

Your neural network can't output a question mark,

can't output a don't care.

So I'll put some numbers for the rest.

But these numbers will basically be ignored because

the neural network is telling you that there's no object there.

So it doesn't really matter whether the output is a bounding box or there's is a car.

So basically just be some set of numbers, more or less noise.

In contrast, for this box over here hopefully,

the value of y to the output for that box at the bottom left,

hopefully would be something like zero for bounding box one.

And then just open a bunch of numbers, just noise.

Hopefully, you'll also output a set of numbers that

corresponds to specifying a pretty accurate bounding box for the car.

So that's how the neural network will make predictions.

Finally, you run this through non-max suppression.

So just to make it interesting.

Let's look at the new test set image.

Here's how you would run non-max suppression.

If you're using two anchor boxes,

then for each of the non-grid cells,

you get two predicted bounding boxes.

Some of them will have very low probability,

very low Pc, but you still get

two predicted bounding boxes for each of the nine grid cells.

So let's say, those are the bounding boxes you get.

And notice that some of the bounding boxes can go

outside the height and width of the grid cell that they came from.

Next, you then get rid of the low probability predictions.

So get rid of the ones that even the neural network says,

gee this object probably isn't there.

So get rid of those.

And then finally if you have three classes you're trying to detect,

you're trying to detect pedestrians, cars and motorcycles.

What you do is, for each of the three classes,

independently run non-max suppression for

the objects that were predicted to come from that class.

But use non-max suppression for the predictions of the pedestrians class,

run non-max suppression for the car class,

and non-max suppression for the motorcycle class.

But run that basically three times to generate the final predictions.

And so the output of this is hopefully that you will have

detected all the cars and all the pedestrians in this image.

So that's it for the YOLO object detection algorithm.

Which is really one of the most effective object detection algorithms,

that also encompasses many of the best ideas across

the entire computer vision literature that relate to object detection.

And you get a chance to practice implementing many components of this yourself,

in this week's problem exercise.

So I hope you enjoy this week's problem exercise.

There's also an optional video that follows this one

which you can either watch or not watch as you please.

But either way I also look forward to seeing you next week.