Hello and welcome to the last step of our process to make the brain we have one function to make left.
This is the forward function that will propagate the signals in all the layers of the neural network
including the three convolutional layers and the fully connected layer.
And so this function is the forward function exactly like for the self-driving car except this time
we have to propagate the signals in the convolutional layers before the fully connected layer.
And the good news is we already did that in the previous step with the count Newnes function.
So we already have the code to propagate the signal in the country.
And so this will be very quick.
We'll just combine what we did here and what we did for the submarine car and we'll get our forward
function for our brain.
So let's do this.
We introduce a new function here the last one for the brain and this function is the forward function
which takes an argument.
Well exactly like before self to refer to the objects and X which will be first the input images and
then you know X will be updated as the signal is propagated into the new network.
All right.
So Cullen and then let's go inside the function.
So as I just said we already made the code to propagate the signals in the three convolutional layers.
That's exactly these three lines of code.
So I'm copying them and pasting them here and there we go.
We already have our propagation of the signal in the three convolutional layers.
And so now we just need to propagate the signal from the convolutional layers to the hidden layer and
then eventually to the output layer that is at the very end of the neural network and to do this we
first need to flatten the third convolutional layer that we obtained here remember X at first is the
input image.
Then here X becomes the first convolutional layer then X becomes the second convolutional there.
And then here X becomes the third convolutional there.
So right now at this stage X is the third convolutional layer.
And now to take the flattening there we need to flatten this third convolutional layer X and to do this
we are going to do something quite similar as we did here only this time we don't need the number of
neurons we simply need to flatten the channels in the third convolutional there.
So this will be quite more simple but very similar.
And to do this well we're going to take X again because X is going to become the flattening layer.
We're just updating X so x equal then we take X again but this X is the old X that is the third convolutional
layer.
So we take the third convolutional there then but then we take the view function to which we apply to
arguments.
The first one is X that size zero.
So again we take the size function to take all the pixels of all the channels and the third convolutional
layer and we put them one after the other in this huge vector that is going to become this X here and
this X then will become the input of the fully connected network.
But that's not all we need to.
And here come up.
And minus one.
So that trick you can find it in the pocket watch tutorials.
That's how you can flatten a convolutional they are composed of several channels by using the size function.
And of course if you want more details on how this works you can go to the pocket watch tutorials.
I will provide the link.
So now that we got our flattening there well you know this flattening is going to become the input of
a classic fully connected network with a simple linear transmission of the signal.
And so now we're not going to use a convolution function to pass on the signal we're going to use a
linear transmission with a linear class and then to break the linearity because when we're working with
images and images have non-linear relationships.
Well we're going to use a rectifiable function to be able to learn these non-linear relationships.
So let's do this.
This is actually the next step.
And so now that's exactly like what we did for the self-driving car.
We take X because we want to update it again we want to get the hidden layer now.
And so first what we do is we take our full connection SE1 because the full connection.
FC one is the one that connects the flattening layer to the hidden there and therefore we need to take
SE1 and apply it to the X that we have right now which is the flooding there.
And we don't forget the self of course because everyone is a variable of our init function.
So self-taught SE1 X and so that passes on linearly the signal from the flatteringly to the hidden there.
But now we need to activate these neurons while at the same time breaking the law in errancy.
And that's exactly what we do with the rectifier activation function.
So now what we have to do is take our functional module and from this functional module we take of course
or rectifiable function that is the real you.
And we put self-taught SE1 inside the parenthesis.
All right so what happens in this line of code is that first we propagate the signals from the flattening
layer to the hidden layer of the fully connected network.
And then we activate the neurons of this hidden layer by breaking in the air with this rectifier activation
function and we get our head in there that is here perfect.
And now we have one last step to do it is of course to propagate the signal from the hidden layer to
the output layer with the final output neurons and to do this.
Well that's very simple.
That's exactly like what we did with the in car.
We take our second full collection of C2 and we apply it to of course the neurons of the hidden layer
that is right now x.
So here is the neurons here and there.
This all x and x here becomes of course the output neurons of the output layer containing the cube values.
And finally we simply return the output neurons that is x with the cube values.
So perfect.
Congratulations we just made a brain we just made the brain of our AI AI with the eyes and the rest
of the cells.
So congratulations.
Now it's time to make the body that is defining how we're going to play the action.
After all the signals are processed in the brain.
So that's our second big step.
Let's do this in the next tutorials.
And until then AI.