‫In the last couple of lectures we learned how to train and create what models one think.
‫You have noticed as each time we opened that you buy the notebook.
‫We started creating and training our models from scratch but we don't have to do that.
‫There is a very simple way to save your model.
‫After you have trained it killed us will save both the model architecture including the every layer
‫but parameters and the value of all the model parameters for each layer that is biases and weights value
‫so instead of creating the model each time you open your department 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 write to add more than name so in the last lecture we created a model with functional
‫API and object name was model.
‫So I am 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 file.
‫All these models are saved in as deep a file format.
‫The extension of that is dot at five so if you just run this you have saved your model and new at present
‫working Barrick tree.
‫So if I open my Barrick tree this is this and you can see my model is here.
‫The name of Martin is and why func underscored more than is the same as I have mentioned.
‫You can see your present working directory.
‫With this come I just have to write but send this symbol and b w Li a sentence for present working better.
‫But 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 then CDE and then the new directory name.
‫So as we have seen I have this more than pleasant in my flat.
‫Now let's just delete the more diluted even
‫so I have deleted the model.
‫And I am also clearing the session off get us
‫now.
‫Again I am loading this model with Lord underscore model my code and the head also you have to just
‫provide the name of the file and I am saving this and another object known as more than 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.
‫By creating regression neural network with functional Libya tests 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 biases when
‫you so you can use it for prediction.
‫Also you can see this is the same prediction that we were getting earlier with functional Libya but
‫you can say 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 of after each epoch.
‫So you don't have to wait for the come to training.
‫You can save your model after each epoch as well.
‫Let's just again delude this model and the station here.
‫I'm just taking a small example of a sequential model to densely and when output layer.
‫I wouldn't be using the same data.
‫Let's just compiling.
‫We are using the same but I meant that as a.
‫Now you can provide this callback parameter while training the more than So earlier we were on deployed
‫in creating data e-books 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 that is checkpoint callback and you have to write gave us the callbacks
‫not models.
‫Checkpoint here I can write the finally but since we are running this model for banning books that means
‫we are generating 10 fighters for each epoch
‫so if I provide a constant file name such as my gate on Morton it will just overwrite the fight for
‫each of this penny box so at then 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 dash 0 1 dot at 5.
‫For the second book I want to save it as model best 0 2 that's fine.
‫And so on the last 10 people.
‫So you can use such variable names in your file name also.
‫So you don't have to manually light each file name
‫so here model is the name that I have given.
‫And this is the variable name which is kept in the loop record so I can write a book and I want the
‫two digits of each book.
‫So for one I want 0 1.
‫So that's why 0 2.
‫D If I wanted three digits.
‫So suppose if I was running for 300 bucks I would want three digits.
‫Zero zero one or hundred or two hundred and fifty two ninety nine.
‫In that case I would have written zero D
‫so let's just create this check point.
‫Callback again.
‫Get us or callbacks thought model check point and then the variable name and inside variable name all
‫so we can get variables you mentioned a friend epoch values.
‫Yes run this and now just drain the mortar.
‫We are using the same method.
‫Wonder Lord fit grinning people validation data and then the quarterback
‫so with each of this epoch I am also saving a model file for that epoch.
‫So if we just go back to our directory we should have and model files.
‫Here you can see we have more than less 0 1 model illustrator to model base than this for first epoch.
‫Secondly both totally book and so on builder 10 people.
‫If I would ever use the single file name such as more that than I did then I wouldn't be getting on
‫the single file because of that e.g. bug that I was or what I could by the next book.
‫When you so remember to use the variable names of each book while creating a modified for each epoch.
‫Now I can load this files similar to the previous time.
‫You just have to write it as thought model Lord Lord modern and the file which we want to load.
‫So just to demonstrate that Let's delete the model and clear the session now.
‫So suppose if I want a file of my ten people a model law.
‫So this is the model I want to export.
‫You can see if important that model so in future also if I am opening the department notebook after
‫three or four days I can just write this model that gave us thought model dot load model and then the
‫modelling to load that model.
‫There is absolutely no need of creating compiling and creating the model once again.
‫We can also use evaluate time.
‫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 validation set during the training you can set the save best only equal to group
‫by creating a checkpoint callback
‫that will only save your model when it's performance on the validation set is best.
‫So suppose all of this then epoch values 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 8.
‫There is no need to create a separate model for all this epoch where lose because generally we want
‫a model corresponding to the best score on the
‫so let us lead the model in creating this structure and here while creating the callback I am also setting
‫the parameter value of save best only equal to crew and then I would be getting only a single model
‫with the name.
‫Best model does the model which is corresponding to the best value of validation is score.
‫So let's just create this checkpoint and then we are creating the model.
‫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 their directory also we have saved this best more than faith.
‫We are just loading and using that more than do you and your performance on that site.
‫No one of the best method to screen your model is to use a little scoping.
‫What I'm referring to a list dropping is that you would run your model for a very large number of epoch
‫values.
‫Suppose here I am using 200 e-books and then I will keep an eye on my validation site score so suppose
‫if after 60 e-books my validation set accuracy is 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 validation site school and then select the best more than that we have got so far so
‫to achieve that we will be needing an another callback which we generally call a list 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 new patients value is the number
‫of epochs after which our screening 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 evaluation site discourse then get us will stop the screening at 63 blocks.
‫So the difference between the 6 2 3 and 4 play 3 is then this is the patients.
‫This the number of epochs get us will wait for any improvement in validation is score so earlier you
‫saw value creating our functional model.
‫We have we have to look at our valuation is 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 stopping 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
‫good 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 the normal callbacks also to save the model.
‫And here we are also using saved best on the barometer as well.
‫So at the end of all this training we wouldn't be getting on the a 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 parameter for the number of e-books run this.
‫Now we are preparing our more.
‫We will be passing creating dataset epochs values.
‫Remember to increase epoch values then the validation data and then callbacks.
‫Again we are passing callbacks in the form of lists.
‫We are first passing over a checkpoint callback and then we are passing over our list stopping callback.
‫Just run this
‫so their training has stopped after 87 epoch This means that there is no need to train it till 200 epoch
‫values.
‫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 then 0 1 3 2 and you can see after 10 in bulk we lose the value is still hovering over
‫zero point three three.
‫That's why it stopped at 80 70 pop value let's just look at our directory.
‫We should have a model with file name on these top model yet.
‫You can see us has already saved the best model.
‫Here with the name Ollie's Top Model.
‫So now the training has a stop.
‫We can use this a list top model to predict and evaluate our future values.
‫You can see the loss on tests that we are getting is 0 1 2 3 1 as compared to our previous lost values
‫of zero point 4 3 7 8 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 our more than then we use callbacks to save our model.
‫At EDC POC value then we learned about the parameter that is saved best only which will 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.