Hello and welcome back to the course and deep learning.
Today we're finally at STEPNELL before full connection.
So what is this step all about.
Well in this step we're adding a whole artificial neural network to our convolutional neural network
so to all of the things that we've done so far which are convolution pooling and flattening.
Now we're adding a whole new.
And then on the back of that how intense is that.
That is just that is something that is definitely something.
And so here we've got the input layer we've got a fully connected plan.
I'll put there and by the way the fully connected Lehre in the artificial neural networks we used to
call them hidden layers and here we're calling them fully connected because they are hidden lairs but
at the same time they're a more specific type of fiddlers that are fully connected in artificial neural
networks hidden letters don't have to be fully connected.
Whereas in convolutional neural networks we're going to be using fully connected letters and that's
why they're generally called fully connected Lares.
And so basically that whole column or vector of outputs that we have after the flattening we're passing
it into the input learned here we've got a very simplified example just for illustration purposes.
And what the main purpose of the artificial neural network is is to combine our features into more attributes
that predict the Klaas's even better.
So we already in our vector of outputs in the Flaten of the flattened result from what we've really
done we have some features encoded in the numbers in that vector and they can already do probably a
pretty good job at predicting what's what's Clauss we're looking at whether it's a dog or a cat or whether
it's a tumor or not a tumor and so on.
But at the same time we know that we have this structure called artificial neural network which is designed
which which has a purpose of dealing with attributes and coming out or dealing with features and coming
up with new attributes and combining attributes together to even better predict things that we're trying
to predict and we know that from the previous parts so why not leverage that.
And that's exactly what the plan here is.
So how about we pass on those values into an artificial neural network and let it even further optimize
everything that we're doing.
And so that's what we're going to be doing.
But let's look at a more realistic example because this one is a bit too simple.
So here we've got a better looking artificial neural network where we have five attributes on the inputs
that we have in the first unless we have six neurons in the second or in the second fully connected
Larry have eight neurons and then we have two outputs one for dog and one for cat.
And so an important thing to talk of for us to talk about here is that why do we have two outputs.
We're kind of used to having only one output in our artificial neural networks Well one output is for
kind of when you're predicting a numerical value when you print when you're running a regression type
of problem.
But when you're doing classification you need an output Proclus except for the exception is when you
have just two clusters like we have two classes here dog and cat and we could have just done one output
and made it a binary output and said One is a dog and zeros a cat and that would have worked totally
fine and actually what you'll see had lunch do that in the practical tutorials and that's how they'll
be structured.
But at the same time if you have more than two categories for instance dogs cats and birds then you
have to have a neuron per every category and that's why we're going to practice with two categories
in this example so that we know what to expect if we ever have more than two categories.
And so what's going to be happening here.
So we've already done all the groundwork we've done the convolution we've done the pooling and the flattening
and now the information is going to go through the artificial neural network so let's have a look at
how the other all happens.
There is information going through from the very start from the moment when the image is processed and
kind convoluted convolved then puled flattened and then through the artificial neural network all four
steps and then a prediction is made and we'll see how this happens in a moment will be very very interesting.
But for now let's just say a prediction is made.
And for instance 80 percent that it's a dog.
But it turns out to be a cat and then an error is calculated.
A.
Well what we used to call accosts cost function in a artificial neural network and we used mean square
error there or in-common illusional neural networks.
It's called a loss function and we use a cross entropy function for that.
And we'll talk about cross entropy and mean squared errors.
In a separate tutorial and how all that happens.
But for knowledge you say we have a lost type of function which tells us how well our network is performing
and we're trying to optimize optimize it or minimize that function to optimize our network.
So the error is calculated and then it's back propagated through the network just like we had in artificial
neural networks is back propagated and the some things are adjusted in the network to help optimize
the performance and the things that are adjusted are as usual the weights in the artificial neural network
are part of those the blue lines that you see here the Cynapsus.
Then also another thing that is adjusted is the feature detectors so we know that we're looking for
features but what if we're looking for the wrong features.
What if this didn't work out because the features are incorrect and so the feature detectors those remember
those little matrices that we had.
That's the three by three matrices.
They are adjusted so that maybe next time it'll be better and let's see what happens.
Type of thing.
And but of course it's all done with a lot of science in the background of a lot of math and it's all
done through a gradient gradient descent of back propagation.
So it's all it's all not just random perturbations it's actually very thought through how it's done.
But nevertheless the feature detectors are adjusted the weights are adjusted and this whole process
happens again and then again the errors back propagate.
And this keeps going on and on and on.
And that's how our network is optimized that's how our network trains on the data.
So the important thing here is that the data goes through the whole area from the very start to the
very end.
Then the error is compared so the error is calculated and then is back propagated.
So same story as with artificial neural networks just a bit longer because of that whole for the first
three steps that we already had.
And now let's have a look at the interesting part the really interesting part how do these two classes
work because Or how do these two output neurons work because before we've always kind of had one output
neuron what happens when we have two.
How does how does this situation of classification or images play out.
Well let's start with the top neuron first going to start with the dog.
How do we the main purpose what we need to do first is we need to understand what weights to assign
to all of these syllabuses that connect to the dog so that we know which of the previous neurons are
actually important for the dog and let's see how that is done.
So let's say hypothetically we've got these numbers in our previous layer of previous fully connected.
In the final fully connected layer.
And again these numbers can be absolutely anything.
They don't have to be that they can be any numbers but just for argument's sake we're going to agree
that we are looking specifically at numbers between 0 and 1.
So it's easier for us to argue these things and understand and one means that that neuron was very confident
that it found this feature and zero is going to mean that that neuron didn't find a feature is looking
for so because at the end of the day these neurons like anything else on this from on this left side
is just looking at features at an image.
This is already very very process.
But still it's detecting a certain feature or a combination of features on the image right before we
can evolve step.
We had kind of recognizable features in the pool set they're less recognizable than they become even
less recognizable in the flattened image.
And then they get combine and so on.
But nevertheless this we're talking about here certain features that are present image or their combination.
So and one which has been passed and this is important has been passed to both the dog and the cat at
the same time to both the output neurons.
So one means that for us for our argument it means that this this neuron has is firing up its It's really
rapidly detecting that feature that you know might be an eyebrow it might be detecting this eyebrow
for again for simplicity sake is detecting this eyebrow.
And is communicate that to the dog run to the cat neuron saying I can see my eyebrow I can see my eyebrow.
And then it's up to the dog and the cat neuron to understand what that means for them.
Right.
And so in this case which neurons are firing up these three neurons are firing up the eyebrow and that
say the nose is saying I can see I can see a big nose and I can see floppy ears.
So it and it's saying that to the dog and to the cat and then what the dog.
And then what happens is we know that this is a dog.
So the dog neuron knows that the answer is it is actually a dog because at the end we're comparing to
the picture or to the label on the picture and when another dog.
So basically the dog neuron is going to say Aha.
So I should be triggered in this case.
So these are neurons they're telling this signal that they're sending to both to me to the dog and the
cat is actually a indication for me that it is a dog.
And throughout these lots and lots and lots of iterations of this happens many times the dog will learn
that these neurons do indeed fire up when the feature belongs to a dog.
On the other hand the cat neuron will know that it's not a cat and it will know that this feature is
firing up and this neuron is telling me it can see floppy ears floppy ears ears.
But at the same time it's not a cat.
So basically to me that's a signal that I should ignore this neuron like and the more that happens the
more the cat neuron is going to ignore this neuron about the floppy ears.
And so basically that that's how through lots and lots of iterations if this happens often.
So this is just one example but if this happens often maybe a one maybe 0.8 0.9 maybe sometimes it won't
fire but overall on average this neuron is lighting up very often when it is indeed a dog the dog neuron
will start attributing higher importance to this neuron.
And so there we go.
That's that's how we're going to signify it.
We're going to say that these three neurons through this iterative process with me with many many many
many samples and many many a remember so a sample is a row in your data set and Apoc is when you go
through your whole dataset again and again and again there are lots and lots of iterations.
This dog neuron learned that this eyebrowed neuron and this big nose neuron and this floppy ear neuron
they all seem to really contribute very well to the classification of what it's looking for and which
is a dog.
So that's how it works.
And again these ears and nose and eyebrows those are very very approximate or like very far fetched
examples because by this stage in this whole convolution conventional neural network it is completely
unrecognizable what they're looking for but at the same time it is something in the features of dogs
or cats or whatever you classify it.
And then so let's move on to the next.
Now we're going to look at the cat neuron but these We're going to remember that these weights are you
know how we've sorted out the dog.
So the dog is kind of like pretty much ignoring all these other neurons one two three four or five but
it's really paying attention to what these three neurons are saying.
Now what is the cat's listening to.
Well whenever it is actually a cat.
Right.
This is this is an example of a situation when it's actually a cat.
So you'll see that this these three neurons 0.9 0.9 and one they're saying something they're saying
something to both the dog and the cat.
And this is again important remember so this output signal goes both ways it's the same right.
It's it's saying one to the dog saying to the cat but then it's up to the dog to the cat to decide whether
to take into account that signal and learn from it or not.
And both the dog and the cat can see that this is a photo I should of put a photo of a cat here but
basically imagine a photo of a cat both a dog and the cat can see that this is actually a cat.
So basically the dog is like OK so these whiskers and these pointy triangle ears and this small size
yes or or maybe this type you know how cats have these things in their eyes their eyes are like little
They're not circles or lines or something like cat eyes.
Basically these cat eyes they're definitely not working for me.
They're not helping me I'll predict because every time these neurons light up the prediction is not
what I'm looking for.
On the other hand the cat is like hmm that's interesting.
Every time these this one lights up it's more most of the time it lights up.
It matches my expectation it matches what I'm looking for.
OK.
I'm going to listen to this guy more than this one.
This one same thing every time it lights up or most of the times it lights up.
I happened to get a good I happened to be rewarded for my prediction because I get it right.
It's a cat.
OK.
I'm going to listen to him more.
You know this one useless to me because he's not actually you know like he's he's not even lighting
up it's a cat but it's he's not lighting up so the opposite is happening.
And this one is well it's a cad but he's not letting up so I'm not gonna listen to him.
But this one when he went what was this the eyes the cat eyes light up we can see I can see that it's
a cat.
It matches most of the time so I'm going to learn from that and I'm going to listen to these three guys
more often than not.
And so basically the cat is listening to these three and it's ignoring the other five and that is how
these final neurons learn which neurons in the final fully connected Lehre to listen to the output neurons
learn which of the fully which are the final fully connected.
There are neurons to listen to.
And that's how they understand.
Basically that's how the features are propagated through the network and conveyed to the output.
And so even though these features of course don't have that much meaning to them like floppy ears or
whiskers.
At the same time they do have some distinctive they are a distinctive feature of that specific class
and that's how the network is trained because we also during remember during the back propagation process
we also adjust the feature detectors so if a feature is useless to the output it's going to it's going
to probably be disregarded because this doesn't happen to one or two stories it happens through thousands
and thousands of iterations.
So with time a feature that is useless to the network is going to be disregarded and replaced with feature
is useful and so at the end of the day in this final layer of neurons you are likely to have lots of
features or combinations of features from the image that are indeed representative or descriptive of
dogs and cats.
And so then once your network is trained up then we this is how it's applied.
So this is the next step like we were trained up our network will this happen.
Let's see what happens when the this network is applied.
So let's say we pass on an image of a dog.
The values are propagated through a network we get certain values.
And so this time the dog and the cat neurons don't know they don't have the image of the dog here they
don't know that it's a dog or a cat.
They have no idea what it is but they have learned to listen to what is being shown here.
Right.
They have learned to listen to dog and listens to these three neurons a cat neuron listens to these
three.
And so the dog neuron looks at one two three and says aha these are pretty high.
So my probability is going to be high that is a dog the cat neuron looks at these three and says OK
these this one is pretty high but these are pretty low.
Interesting.
So my probability is going to be 0.05.
And and then and that's.
And that's where you get your prediction.
So then your first choice for this neural network is dog.
Second choice is cat and that's pretty much it.
So the answer is dog and same thing happens when you pass an image of a cat.
You get new values and you can see that even though this one's high these ones are low.
And for the cat This was high this was high and this one's a bit low.
So the probability here might not be as great as previously but still you can see that it's a cat of
79 percent.
And so therefore the neural network is going to vote that it's a cat.
And so basically all the neural networks going to conclude that it's a cat.
Voting is a term that is used for these guys so these neurons in the final fully connected Lehre they
get to vote.
And these are their votes.
And again we are just for argument's sake putting values between 0 and 1 here.
These could be any values but they get to vote and then these weights are the importance of their vote.
So this is these are these purple weights are how the dog neuron views their votes.
How much importance is it assigns to these neurons and those votes.
And this is how much importance the cat's neuron up size to these votes the votes of these neurons and
so these neurons vote the dog and the cat based on their learned the weights they decide who to listen
to and then they make their predictions and then hold neural network concludes that this is in this
case a cat and then that's And then that's your conclusion and that's how you get images like this where
you have a cheetah and then you have a cheetah claws who you know like a high high probability So this
is you know the probability that the network has predicted.
And these are laws but these still exist because they're still kind of like a small chance the other
neurons are also listening to their voters and they're saying oh maybe it's actually a leopard and a
bullet train.
Very very probable.
I hear scissors.
You know this one one but hand-glass was a very close second and in fivepence stethoscope because you
could see like this guy this this neuron the scissors neuron the output series neuron listened to its
voters and it had the predominant vote overall.
But then the hand-glass had a good outcome as well.
So there we go that's how the full connection works and how this is all this all plays out together.
I hope you enjoyed today's tutorial.
We're going to summarize all of this in the summary as well.
And I'll see you next time.
Until then enjoy deep learning.