In the last couple of lectures, we learned how to train and create what Mortons?
One thing you have noticed is each time we opened the door by the notebook, we started creating and
training our models from scratch.
But we don't have to do that.
That is a very simple way to save your model after you have trained it.
Kill us will save both the mortal architecture, including the every layer put parameters and the value
of all the modern parameters for each layer that is biases and weights.
Well, you.
So and sort of greening the model each time you open your dupatta notebook or initiate a new session.
You can just load the model that you have previously saved to get all the details of that.
More than.
Now, saving model is very easy.
You just have to right, you are more than Lahm.
So in the last lecture, we created a model with functional LaPier and object name was model.
So I'm saving that same object so I can write model dot save.
Save is the keyword.
And in the parenthesis, you have to write the name that you want to give to that fight.
All this models are saved in ads beep at five, formic the extension of their test dot at five.
So if you just run this, you have saved your Morden and Newa pleasant working battery.
So if I open my battery, this is this and you can see my model is here.
And the name of models and web func underscore model is the same as I have mentioned.
You can see your present working directory with this.
Come on.
Just step two.
Right.
But since December I.
BWB descends for present working directory.
So if you run this, you will get the directory location.
And in that directory you can find the model that you have saved.
Now, in case you want to change your or indirectly, you can do it with this keyword.
You have to write percentage 10 Sudi and then the new directory name.
So as we have seen, I have this more than present in my folder.
Now let's just delete the model rate even.
So I believe more than an hour.
I'm also clearing the session off guitars.
Now, again, I am loading this mortal with Lord underscore more than my third.
And here also you have to just provide the name of the file.
And I'm saving this and another object known as modern.
Let's just try loading the model that we have recently saved.
Now we can call the summary matter.
This should give me the summary that we saw earlier while creating regression neural network with functional
LaPier.
Just run this.
You can see that we have the same somebody.
Remember, we believe data were more than.
And then we loaded it using the same version.
Now somebody is just the architecture of that model.
You can also predict using this model because it already have the optimized weights and bytes as well.
So you can use it for prediction on.
So you can see.
This is the same prediction that we were getting earlier.
With functional LaPier.
But you can save one model only after the completion of its training.
But usually we have a very large dataset which can take up to eight to 10 hours just to train the model
for that scenario.
We can use callbacks.
You can think of callbacks as check points, which will allow you to save your model after each epoch.
So you don't have to wait for the complete training.
You can save your model after each epoch as well.
Let's just again delete this model and.
Your decision here?
I'm just taking a small example of a sequential model to Bensley.
And when all clear.
I wouldn't be using the same data.
Let's just compiling.
We are using the same parameters as earlier.
Now, you can provide this callback parameter by training the model.
So earlier we were only providing training, data, epochs and validation dataset.
Now, along with this, we can also put away callbacks.
So you have to write callbacks and then here you can provide the list of callbacks that you have created.
This is how you create a callback.
So this is what a variable name is.
Check point callback.
And you have to write give us the callbacks DOT model checkpoint.
Here I can write the filing.
But since.
We are running this model for banning books.
That means we are generating 10 files for each epoch.
So if I provide a concern, find names such as my get out more than it will just override the file for
each of these tiny box.
So, again, I would be only getting a single file of my 10 people
now to resolve this problem.
We can use these variables.
So for one epoch, I want to save my file as model this zero one dot at five for the second Depok.
I want to save it as Mordred best.
Zero two.
That's fine.
And so on.
The last 10 people.
So you can use such variable names in your filing also.
So you don't have to manually light each filing.
So here model is the name that I have given.
And this is the variable name which is kept in the Gotlieb record, so I can write a book and I want
the two digits of each book.
So for one, I want zero one.
So that's why zero to be if I wanted three digits.
So suppose if I was running for 300 bucks I would want three digits.
Zero zero one or a hundred or a hundred and fifty to ninety nine.
In that case I would have written zero 3D.
So let's just cleared this checkpoint, call back again.
Crosstalk Fallbacks Dort model checkpoint and then the variable name and inside variable name.
Also, we can give variables.
You mentioned different epoch values.
Yes.
Run this.
And now just drain the water.
We are using the same method wanderlust fit training people, validation data.
And then the callback.
So with each of this epoch, I'm also saving a model file for that epoch.
So if we just go back to our directory, we should have 10 model files.
Here you can see we have a model that's zero one more or less.
Zero to model.
Less than.
This for First Époque.
Secondly, Poque holy book and sworn killed 10 people.
If I would ever use the single file name, such as murder, then and then I would be getting on the
single file because of very easy pop.
That file was over.
I could buy the next book when you.
So remember to use the variable names of Epoch while creating a model file for Epoch.
Now, I can load this files similar to the previous time.
We just have to.
Right.
He does talk more a lot.
Lord Morton.
And the file, which we want to load.
So just to demonstrate that, let's believe the modern clear position now.
So suppose if I won five of my ten people, so modern law.
So this is the model I want to export.
You can see imported that model.
So in future, also, if I'm opening this, you buy a notebook of that three or four days.
I can just write this model.
Gave us dot model, dot load model.
And then the mordantly to load that model.
There is absolutely no need of creating, compiling and creating the model once again.
We can also use evaluate method.
You can see this model object is working.
Now there is no need of saving the model.
At each epoch, if you are using the regulations set during the training, you can set the safe best
only equal to true value, creating a checkpoint called the back.
It will only save your more than when its performance on the validation set is best.
So suppose out of this then epoch will lose.
We were getting the best validation is scored, I suppose, epoch.
Then in the final fight, we will be getting the model corresponding to Epoch eight.
There is no need to create a separate model for all this epoch values.
Because generally, we want the model corresponding to the best score on the.
So let us believe the model in creating a structure.
And here, while creating the callback, I am also setting the parameter well, your safe best, only
equal to crawl.
And then I would be getting only a single more done with the name.
Best model.
The model, which is corresponding to the best value of validation, is called.
So let's just create this point.
And then we are creating the more than, again, extreme epochs validation set and then the callbacks.
Now, to get the best model, we can just import the best model that we have saved.
So if you see in there that are cool.
So we have saved this best mardon daughter.
We are just loading and using that model.
Do you and your performance on test set?
No one of the best method to scream your murder is to use a little stopping.
What I'm referring at least stopping, is that you would run your model for a very large number of epoch
values.
Suppose here I am using two hundred epochs.
And then I will keep an eye on my validation, said Skort.
So suppose if after 60 epochs, my relevation said accuracy's, not improving, then I will stop the
training at that point and I will be using the model with the best validation is, quote, so far.
So this is an ideal situation.
We don't have to worry about how many books we want to run.
We just set a very high value of people.
We monitor the valuations are Disko and then select the best model that we have got so far.
So to achieve that, we will be needing and another callback, which we generally call at least stopping
callback.
And we will use this callback along with our normal callback of safe, best only model.
So in a list topping callback, we have to provide the patients value.
Patients value is the number of epochs after which our training will be interrupted if there is no progress
on the validation set score.
So suppose after 53 epochs, we are not getting any improvement on our evaluations or discourse.
Then get us will stop the training at six three.
So the difference between the sexy three and four P3 is ten.
This is the patients.
Thus the number of epochs scared us will wait for any improvement in validation is called.
So earlier you saw value creating our functional model.
We have we have to look at our valuation score graph to check out whether our model is converging or
not.
Now, we don't have to worry about that.
We can use a list scoping along with other callbacks, which will automatically save the best model
that is available.
And it will also train our model for optimal amount of time needed to create that model to its best
accuracy score.
So let's just run this.
We are first creating this structure now, along with barely stopping callback.
We have to use over the normal callbacks also to save the model.
And here we are also using save best on Leape barometer as well.
So at the end of all this training, we would be getting on the single model file on which we would
be getting the best validation service score.
Now our second callback is a list stopping callback.
Here you have to provide patients parameters for the number of epochs.
Run this.
Now we have Ukraine.
Our model will be passing screening dataset, epochs, values.
Remember to increase epoch values.
Then the validation data and then callbacks.
Again, we are passing callbacks in the form of list.
We are first passing over a checkpoint callback and then we are passing over at least stopping callback.
Just run this.
So their training has stopped after 87 epoch.
This means that there is no need to train it, two 200 people could lose.
Our model has already converged and there is no way to further decrease the validation loss.
You can see the best value we are getting is that 70 70 book, and it waited for 10 more epochs to get
the better value than zero point three two.
And you can see up to 10 Époque will.
The value is still hovering over zero point three three.
That's why it is stopped at 87 Depok value.
Let's just look at our directory.
We should have a modern with file name on this top model here.
You can see it US has already saved the best model here with the name of the top model.
So now the training has to stop.
We can use this at least top model to predict and evaluate our future values.
You can see the loss on tests that we are getting is zero point two three one as compared to our previous
loss values of zero point four three seven, eight and so on.
So using only stop callback is a very good way to optimize performance of your model.
You don't have to worry about the number of epochs.
So let's have a quick recap of what we learned in this lecture.
First, we learn how to save and load over more than than we used callbacks to save our model at each
epoch value.
Then we learned about a parameter that is saved best only, which can save the model for which we are
getting the best accuracy score or lowest validation loss.
And after that, we saw how to use only a stop callback to terminate the training if no progress on
validation loss is occurring.
So that's all for this lecture.
Thank you.