WEBVTT

00:00.390 --> 00:02.490
-: Hello, and welcome to the last step

00:02.490 --> 00:04.560
of our process to make the brain.

00:04.560 --> 00:06.420
We have one function to make left.

00:06.420 --> 00:10.230
This is the forward function that will propagate the signals

00:10.230 --> 00:12.480
in all the layers of the neural network,

00:12.480 --> 00:14.610
including the three convolution layers

00:14.610 --> 00:16.350
and the fully connected layer.

00:16.350 --> 00:18.660
And so this function is the forward function

00:18.660 --> 00:20.700
exactly like for the self-driving car,

00:20.700 --> 00:23.850
except this time we have to propagate the signals

00:23.850 --> 00:27.600
in the convolution layers before the fully connected layer.

00:27.600 --> 00:30.030
And the good news is we already did that

00:30.030 --> 00:32.610
in the previous step with the count neurons function.

00:32.610 --> 00:35.760
So we already have the code to propagate this signal

00:35.760 --> 00:37.320
in the convolution layers.

00:37.320 --> 00:38.910
And so this will be very quick.

00:38.910 --> 00:40.710
We will just combine what we did here

00:40.710 --> 00:42.570
and what we did for the self driving car

00:42.570 --> 00:45.750
and we'll get our forward function for our brain.

00:45.750 --> 00:46.830
So let's do this.

00:46.830 --> 00:48.690
We introduce a new function here.

00:48.690 --> 00:51.000
The last one for the brain

00:51.000 --> 00:55.140
and this function is the forward function,

00:55.140 --> 00:57.120
which states as argument,

00:57.120 --> 00:59.370
well exactly like before self

00:59.370 --> 01:00.870
to refer to the object.

01:00.870 --> 01:05.250
And X, which will be first the input images,

01:05.250 --> 01:07.200
and then you know, X will be updated,

01:07.200 --> 01:10.620
as the signal is propagated into the neural network.

01:10.620 --> 01:14.340
All right, so colon, and then let's go inside the function.

01:14.340 --> 01:17.130
So as I just said, we already made the code

01:17.130 --> 01:20.520
to propagate the signals in the three convolution layers.

01:20.520 --> 01:23.580
That's exactly these three lines of code.

01:23.580 --> 01:25.890
So I'm copying them

01:25.890 --> 01:28.230
and facing them here.

01:28.230 --> 01:29.063
And there we go.

01:29.063 --> 01:32.340
We already have our propagation of the signal

01:32.340 --> 01:34.470
in the three convolution layers.

01:34.470 --> 01:37.800
And so now we just need to propagate the signal

01:37.800 --> 01:40.710
from the convolution layers to the hidden layer

01:40.710 --> 01:42.810
and then eventually to the output layer

01:42.810 --> 01:45.360
that is at the very end of the neural network.

01:45.360 --> 01:48.540
And to do this, we first need to flatten

01:48.540 --> 01:51.030
the third convolution layer that we obtained here.

01:51.030 --> 01:54.690
Remember X at first is the input image.

01:54.690 --> 01:58.140
Then here X becomes the first convolution layer.

01:58.140 --> 02:00.900
Then here X becomes the second convolution layer,

02:00.900 --> 02:03.930
and then here X becomes the third convolution layer.

02:03.930 --> 02:07.770
So right now at this stage X is the third convolution layer.

02:07.770 --> 02:09.810
And now to obtain the flattening layer

02:09.810 --> 02:14.280
we need to flatten this third convolution layer X.

02:14.280 --> 02:15.990
And to do this, we are gonna do

02:15.990 --> 02:18.240
something quite similar as we did here.

02:18.240 --> 02:20.940
Only this time, we don't need the number of neurons.

02:20.940 --> 02:23.340
We simply need to flatten the channels

02:23.340 --> 02:25.110
in the third convolutional layer.

02:25.110 --> 02:28.440
So this will be quite more simple, but very similar.

02:28.440 --> 02:32.040
And to do this while we're going to take X again,

02:32.040 --> 02:35.820
because X is going to become the flattening layer.

02:35.820 --> 02:37.560
So we're just updating X,

02:37.560 --> 02:40.440
so X equal, then we take X again,

02:40.440 --> 02:42.720
but this X is the old X,

02:42.720 --> 02:44.520
that is the third convolution layer.

02:44.520 --> 02:47.130
So we take the third convolution layer,

02:47.130 --> 02:50.490
then dot, then we take the view function

02:50.490 --> 02:52.500
to which we apply two arguments.

02:52.500 --> 02:56.070
The first one is X dot size zero.

02:56.070 --> 02:58.560
So again, we take the size function to

02:58.560 --> 03:00.720
take all the pixels of all the channels

03:00.720 --> 03:02.490
in the third convolutional layer.

03:02.490 --> 03:05.310
And we put them one after the other in this huge vector

03:05.310 --> 03:07.170
that is going to become this X here.

03:07.170 --> 03:09.660
And this X then will become the input

03:09.660 --> 03:11.460
of the fully connected network.

03:11.460 --> 03:13.770
But that's not all we need to add here,

03:13.770 --> 03:16.170
comma and minus one.

03:16.170 --> 03:19.320
So that trick, you can find it in the PyTorch Tutorials.

03:19.320 --> 03:21.930
That's how you can flatten a convolution layer

03:21.930 --> 03:25.170
composed of several channels by using the size function.

03:25.170 --> 03:27.990
And of course, if you want more details on how this works

03:27.990 --> 03:30.000
you can go to the PyTorch Tutorials,

03:30.000 --> 03:31.770
I will provide the link.

03:31.770 --> 03:34.530
So now that we got our flattening layer,

03:34.530 --> 03:35.940
well you know this flattening layer

03:35.940 --> 03:39.360
is going to become the input of a classic,

03:39.360 --> 03:42.120
fully connected network with a simple linear

03:42.120 --> 03:43.770
transmission of the signal.

03:43.770 --> 03:47.070
And so now we're not gonna use a convolution function

03:47.070 --> 03:48.390
to pass on the signal.

03:48.390 --> 03:51.660
We're gonna use a linear transmission with the linear class

03:51.660 --> 03:53.670
and then to break the linearity,

03:53.670 --> 03:55.500
because you know we're working with images,

03:55.500 --> 03:57.870
and images have non-linear relationships,

03:57.870 --> 04:00.510
well we're gonna use a rectify function

04:00.510 --> 04:03.480
to be able to learn these non-linear relationships.

04:03.480 --> 04:04.530
So let's do this.

04:04.530 --> 04:06.150
This is actually the next step.

04:06.150 --> 04:07.950
And so now that's exactly like what we did

04:07.950 --> 04:09.330
for the self-driving car.

04:09.330 --> 04:12.060
We take X because we want to update it again,

04:12.060 --> 04:15.060
we want to get the hidden layer now.

04:15.060 --> 04:18.480
And so first what we do is we take our full

04:18.480 --> 04:19.980
connection FC one,

04:19.980 --> 04:22.380
because the full connection FC one is the one

04:22.380 --> 04:25.530
that connects the flattening layer to the hidden layer.

04:25.530 --> 04:28.650
And therefore we need to take FC one,

04:28.650 --> 04:31.140
and apply it to the X that we have right now,

04:31.140 --> 04:32.970
which is the flattening layer.

04:32.970 --> 04:36.030
And we don't forget the self, of course,

04:36.030 --> 04:38.850
because FC one is a variable of our in it function.

04:38.850 --> 04:40.830
So self.FCone x.

04:40.830 --> 04:43.380
And so that passes on linearly the signal

04:43.380 --> 04:45.660
from the flattening layer to the hidden layer.

04:45.660 --> 04:47.610
But now we need to activate these neurons,

04:47.610 --> 04:50.100
while at the same time breaking the linearity.

04:50.100 --> 04:51.270
And that's exactly what we do

04:51.270 --> 04:53.460
with the rectifier activation function.

04:53.460 --> 04:54.990
So now what we have to do

04:54.990 --> 04:58.200
is take our functional module

04:58.200 --> 04:59.580
and from this functional module,

04:59.580 --> 05:02.850
we take of course our rectify function,

05:02.850 --> 05:04.170
that is the relu

05:04.170 --> 05:08.160
and we put cell.FC1 inside the parenthesis.

05:08.160 --> 05:10.800
All right, So what happens in this line of code is that,

05:10.800 --> 05:13.500
first we propagate the signals

05:13.500 --> 05:15.600
from the flattening layer to the hidden layer

05:15.600 --> 05:17.550
of the fully connected network.

05:17.550 --> 05:20.820
And then we activate the neuron of this hidden layer

05:20.820 --> 05:23.340
by breaking the linearity with this rectify

05:23.340 --> 05:24.780
your activation function.

05:24.780 --> 05:28.440
And we get our hidden layer that is X here.

05:28.440 --> 05:31.170
Perfect, and now we have one less step to do.

05:31.170 --> 05:33.600
It is of course, to propagate the signal

05:33.600 --> 05:36.990
from the hidden layer to the output layer

05:36.990 --> 05:38.850
with the final output neurons.

05:38.850 --> 05:41.130
And to do this well, that's very simple.

05:41.130 --> 05:43.650
That's exactly like what we did for the self-driving car.

05:43.650 --> 05:47.670
We take our second full connection, FC two,

05:47.670 --> 05:50.190
and we apply it to, of course,

05:50.190 --> 05:53.730
the neurons of the hidden layer that is right now, X.

05:53.730 --> 05:56.010
So X here is the neurons of the hidden layer,

05:56.010 --> 05:57.150
this old X.

05:57.150 --> 06:00.090
And X here becomes, of course, the output neurons

06:00.090 --> 06:03.180
of the output layer containing the Q values.

06:03.180 --> 06:07.470
And finally, we simply return the output neurons

06:07.470 --> 06:10.290
that is X with the Q values.

06:10.290 --> 06:12.210
So perfect, congratulations.

06:12.210 --> 06:13.830
We just made a brain.

06:13.830 --> 06:15.870
We just made the brain of our AI

06:15.870 --> 06:17.790
with the eyes and the rest of the cells.

06:17.790 --> 06:19.140
So congratulations.

06:19.140 --> 06:22.050
Now it's time to make the body that is defining how

06:22.050 --> 06:23.490
we're gonna play the action.

06:23.490 --> 06:26.700
After all, the signals are processed in the brain.

06:26.700 --> 06:28.380
So that's our second big step.

06:28.380 --> 06:30.270
Let's do this in the next tutorials.

06:30.270 --> 06:32.103
And until then, enjoy AI.
