In the last video we broke down what's going on here.
What we're doing is essentially just passing Kerry's sequential model and input a.k.a. our image of
a dog and then mobile Net V2 a.k.a. this model you are all that we're using is going to find the patterns
inside it and then we're going hey no we don't want the same shape as mobile Net V2 we'd rather convert
it to the size of our own output shape which is the amount of labels that we have with the amount of
unique labels that we have.
So now let's talk about what's going on in compile.
And by the way if you do want to dive deeper on any of this I encourage you to search it up and figure
it out and try out yourself.
We're going to see the outputs of this later on.
So we're going to actually see the code running but whenever you look up something and try to figure
it out even if you don't understand it the first time trying to figure things out for yourself is a
way to really cement your knowledge.
So if anything here you want to look up and find more.
Don't be afraid to ask questions and don't be afraid to look it up and check it out what's going on
behind the scenes for yourself.
Now what is happening with model dot compile this is something else you'll see when we're building a
model with carers and so I think this one is best explained with a story let's say you're at the International
Hill descending championships.
That's right.
Your one of the world's best at going down hills and you start standing on the top of a hill and now
your goal is to get to the bottom of the hill but the catch is that you're blindfolded and luckily your
friend Adam is standing at the bottom of the hill shouting instructions at you on how to get down and
at the bottom of the hill there's a judge evaluating how well you're doing.
They know where you need to end up.
So they can pair how you're doing to where you're supposed to be and their comparison is how you get
scored a.k.a. your accuracy at getting down the hill you might be wondering.
Daniel why am I at the International Hill descending championships.
Well let me break it down this is where the model dot compile comes into play.
Let's channel into this terminology because this can seem very confusing when you first begin.
So the loss so the loss is the height of the hill.
Now our model's goal is to minimize the loss getting it to zero a.k.a. getting to the bottom of the
hill.
So this means that the model is learning perfectly.
Loss is a measure of when the model is learning.
So when it's going through the training set and comparing the image to a label the loss is a measure
of how well the model is guessing.
So when it's trying to make a prediction what is this learning the higher the loss the worse the prediction
is.
So the worse the model is learning patterns the lower the loss the better the model is learning patterns
just like you if you're descending the hill the higher you are on the Hill at the International Hill
descending championships the higher you are the worse off you're doing.
So your goal is to get to the bottom of the hill.
And now if we come back let's discuss what the optimizer is in our Hill story so your friend Adam at
the bottom of the Hill who's telling you how to get down the hill is the optimizer he is the one telling
you how to navigate the hill a.k.a. lower the lost function.
So how high you are on the Hill because he can see what's going on.
He can see your movements so he's basing his instructions on what you've done so far and now his name
is Adam your friend's name is Adam because the Adam optimizer Yes it's actually called the Adam optimizer
is a great general optimizer which performs well on most models so if we have a look at this we go to
Adam optimizer Adam the latest trends in deep learning gentle instruction for Adam optimization and
if we go machine learning model optimizes it's gonna tell us a few more types of optimization algorithms.
So this is what's going on here.
The lost function is how high you are on the Hill you're trying to minimize that because you're at the
International Hill descent championships.
The optimizer is your friend Adam at the bottom.
You can also use another optimizer called ALM s prop or stochastic gradient descent but generally to
begin with Adam is pretty good on most problems.
So Adam's telling you how to get down the hill because rember you're blindfolded you're a model who's
going through the training data for the first time and trying to learn patterns or trying to go down
the bottom of the hill for the first time blindfolded.
And then finally the metrics here.
This is the on look at the bottom of the hill.
This is the judge of how well your performance is at the bottom of the hill telling you how you're going
at the championship.
So in our case it's giving us the accuracy of how well our model is predicting the correct image label.
So that's a fair bit to go through but these are three parts of most deep learning models.
Basically all of them you're going to have some sort of lost function.
So how well your model is guessing you're gonna have an optimizer function so a function that helps
your model improve its guesses and then a metric which is a way of evaluating those guesses after it's
learned.
So this is a step that we're gonna have to take with when we're building any carries deep learning model.
We define the model as some sort of layers and then we define how the model is going to learn so hold
onto that little story.
If you have any questions about the story or if you want to figure out what lost function and want to
use search up something like what loss function should I use how to choose loss functions when training
deep learning models beautiful is a great resource or it might be.
I'll leave a resource there how you can choose a lost function but mostly it's going to depend on what
problem you're dealing with.
So if you're using binary classification a.k.a. if you're predicting whether something is one thing
or another such as images of cats or dogs you would want to change your activation function to sigmoid
and then your loss function to binary cross entropy.
So we change this to binary cross entropy but because we're doing multi class we keep it at categorical
cross entropy because if we come here multi class classification activation soft Max loss categorical
cross entropy.
Now this is a lot to take on.
So don't worry if you don't get it to begin with.
But remember the whole story.
Remember what the loss is.
Remember what the optimizer is just your friend Adam telling you how to walk down the hill and the metrics
you could use a bunch of different metrics here.
So we go here TAF carer's metrics is gonna tell you some metrics that you can use.
Accuracy is the default one for classification but we've got area under the curve categorical accuracy
a whole bunch.
Main precision recall so a whole bunch of different options I'll be sure to link those as well but that
we've gone through what compiling the model does and then finally we can finish off with this one because
building I think you can imagine what's happening here is just another little way to say hey this is
the input shape we're going to take to our model.
So we're using a carer's layer from tensor flow hub.
And if we come back to here it says that if we want to use this layer we set up a sequential model and
then build the model with our input shape and it's this shape because that is the size of images that
mobile Net V2 was trained on all right now that has been enough talking we've broken down what our create
model function does.
If you have any questions be sure to leave it in the question and answer or in the discord chat but
let's have a look at what's going on.
Well probably actually in the next video just quickly debrief what's going on in summary.
But the next thing we want to do is create some callbacks for our model.
So while our model is training callbacks are gonna be some functions that are going to implement a few
little helpful things that our model can do while it's learning patterns in the data.
So I'll see you in the next video.