﻿1
00:00:01,020 --> 00:00:09,710
‫In the last couple of lectures we learned how to train and create what models one think.

2
00:00:09,720 --> 00:00:15,240
‫You have noticed as each time we opened that you buy the notebook.

3
00:00:15,240 --> 00:00:24,500
‫We started creating and training our models from scratch but we don't have to do that.

4
00:00:24,520 --> 00:00:27,690
‫There is a very simple way to save your model.

5
00:00:27,820 --> 00:00:35,880
‫After you have trained it killed us will save both the model architecture including the every layer

6
00:00:36,020 --> 00:00:45,380
‫but parameters and the value of all the model parameters for each layer that is biases and weights value

7
00:00:47,860 --> 00:00:54,670
‫so instead of creating the model each time you open your department notebook or initiate a new session

8
00:00:55,240 --> 00:01:03,280
‫you can just load the model that you have previously saved to get all the details of that more than

9
00:01:05,420 --> 00:01:07,950
‫now saving model is very easy.

10
00:01:08,000 --> 00:01:15,330
‫You just have to write to add more than name so in the last lecture we created a model with functional

11
00:01:15,330 --> 00:01:18,360
‫API and object name was model.

12
00:01:18,630 --> 00:01:23,870
‫So I am saving that same object so I can write model Dot.

13
00:01:23,880 --> 00:01:25,480
‫Save save is the keyword.

14
00:01:26,100 --> 00:01:31,800
‫And in the parenthesis you have to write the name that you want to give to that file.

15
00:01:33,180 --> 00:01:37,930
‫All these models are saved in as deep a file format.

16
00:01:38,250 --> 00:01:49,600
‫The extension of that is dot at five so if you just run this you have saved your model and new at present

17
00:01:49,660 --> 00:01:52,340
‫working Barrick tree.

18
00:01:52,600 --> 00:02:03,590
‫So if I open my Barrick tree this is this and you can see my model is here.

19
00:02:03,670 --> 00:02:12,200
‫The name of Martin is and why func underscored more than is the same as I have mentioned.

20
00:02:12,490 --> 00:02:14,780
‫You can see your present working directory.

21
00:02:14,950 --> 00:02:24,120
‫With this come I just have to write but send this symbol and b w Li a sentence for present working better.

22
00:02:24,380 --> 00:02:31,810
‫But if you run this you will get the directory location and in that directory you can find the model

23
00:02:31,870 --> 00:02:32,740
‫that you have saved.

24
00:02:34,480 --> 00:02:41,650
‫Now in case you want to change your or indirectly you can do it with this keyword.

25
00:02:41,800 --> 00:02:48,200
‫You have to write percentage then CDE and then the new directory name.

26
00:02:48,200 --> 00:02:53,510
‫So as we have seen I have this more than pleasant in my flat.

27
00:02:53,560 --> 00:02:57,010
‫Now let's just delete the more diluted even

28
00:03:00,430 --> 00:03:02,430
‫so I have deleted the model.

29
00:03:02,710 --> 00:03:06,040
‫And I am also clearing the session off get us

30
00:03:08,860 --> 00:03:09,190
‫now.

31
00:03:09,190 --> 00:03:17,920
‫Again I am loading this model with Lord underscore model my code and the head also you have to just

32
00:03:17,920 --> 00:03:26,680
‫provide the name of the file and I am saving this and another object known as more than let's just try

33
00:03:26,890 --> 00:03:31,800
‫loading the model that we have recently saved.

34
00:03:32,140 --> 00:03:34,120
‫Now we can call the summary matter.

35
00:03:34,120 --> 00:03:38,740
‫This should give me the summary that we saw earlier.

36
00:03:38,750 --> 00:03:49,420
‫By creating regression neural network with functional Libya tests run this you can see that we have

37
00:03:49,420 --> 00:03:59,650
‫the same somebody remember we believe data were more than and then we loaded it using the same version.

38
00:03:59,980 --> 00:04:03,750
‫Now somebody is just the architecture of that model.

39
00:04:03,910 --> 00:04:12,250
‫You can also predict using this model because it already have the optimized weights and biases when

40
00:04:12,280 --> 00:04:15,870
‫you so you can use it for prediction.

41
00:04:15,870 --> 00:04:25,650
‫Also you can see this is the same prediction that we were getting earlier with functional Libya but

42
00:04:26,100 --> 00:04:37,590
‫you can say one model only after the completion of its training but usually we have a very large dataset

43
00:04:38,370 --> 00:04:45,870
‫which can take up to eight to 10 hours just to train the model for that scenario.

44
00:04:45,870 --> 00:04:49,920
‫We can use callbacks.

45
00:04:50,340 --> 00:04:59,550
‫You can think of callbacks as check points which will allow you to save your model of after each epoch.

46
00:05:00,540 --> 00:05:04,030
‫So you don't have to wait for the come to training.

47
00:05:04,110 --> 00:05:07,930
‫You can save your model after each epoch as well.

48
00:05:09,810 --> 00:05:18,480
‫Let's just again delude this model and the station here.

49
00:05:18,620 --> 00:05:24,710
‫I'm just taking a small example of a sequential model to densely and when output layer.

50
00:05:24,790 --> 00:05:26,330
‫I wouldn't be using the same data.

51
00:05:27,310 --> 00:05:29,050
‫Let's just compiling.

52
00:05:29,260 --> 00:05:33,310
‫We are using the same but I meant that as a.

53
00:05:34,030 --> 00:05:42,340
‫Now you can provide this callback parameter while training the more than So earlier we were on deployed

54
00:05:42,350 --> 00:05:46,060
‫in creating data e-books and validation dataset.

55
00:05:46,420 --> 00:05:51,230
‫Now along with this we can also put away callbacks.

56
00:05:51,550 --> 00:06:01,150
‫So you have to write callbacks and then here you can provide the list of callbacks that you have created.

57
00:06:01,150 --> 00:06:03,330
‫This is how you create a callback.

58
00:06:03,370 --> 00:06:10,990
‫So this is what a variable name that is checkpoint callback and you have to write gave us the callbacks

59
00:06:11,240 --> 00:06:12,160
‫not models.

60
00:06:12,180 --> 00:06:23,760
‫Checkpoint here I can write the finally but since we are running this model for banning books that means

61
00:06:23,820 --> 00:06:27,480
‫we are generating 10 fighters for each epoch

62
00:06:30,170 --> 00:06:38,240
‫so if I provide a constant file name such as my gate on Morton it will just overwrite the fight for

63
00:06:38,240 --> 00:06:46,590
‫each of this penny box so at then I would be only getting a single file of my 10 people.

64
00:06:49,210 --> 00:06:54,430
‫Now to resolve this problem we can use these variables.

65
00:06:54,550 --> 00:07:04,130
‫So for one epoch I want to save my file as model dash 0 1 dot at 5.

66
00:07:04,270 --> 00:07:09,820
‫For the second book I want to save it as model best 0 2 that's fine.

67
00:07:10,360 --> 00:07:12,810
‫And so on the last 10 people.

68
00:07:13,180 --> 00:07:17,730
‫So you can use such variable names in your file name also.

69
00:07:18,040 --> 00:07:21,880
‫So you don't have to manually light each file name

70
00:07:24,870 --> 00:07:28,590
‫so here model is the name that I have given.

71
00:07:28,770 --> 00:07:36,300
‫And this is the variable name which is kept in the loop record so I can write a book and I want the

72
00:07:36,420 --> 00:07:38,130
‫two digits of each book.

73
00:07:38,310 --> 00:07:40,450
‫So for one I want 0 1.

74
00:07:40,500 --> 00:07:41,880
‫So that's why 0 2.

75
00:07:41,880 --> 00:07:44,790
‫D If I wanted three digits.

76
00:07:44,810 --> 00:07:50,910
‫So suppose if I was running for 300 bucks I would want three digits.

77
00:07:50,920 --> 00:07:56,270
‫Zero zero one or hundred or two hundred and fifty two ninety nine.

78
00:07:56,310 --> 00:07:59,490
‫In that case I would have written zero D

79
00:08:02,380 --> 00:08:05,160
‫so let's just create this check point.

80
00:08:05,230 --> 00:08:06,820
‫Callback again.

81
00:08:06,850 --> 00:08:12,330
‫Get us or callbacks thought model check point and then the variable name and inside variable name all

82
00:08:12,360 --> 00:08:17,920
‫so we can get variables you mentioned a friend epoch values.

83
00:08:18,310 --> 00:08:22,340
‫Yes run this and now just drain the mortar.

84
00:08:22,500 --> 00:08:24,960
‫We are using the same method.

85
00:08:25,060 --> 00:08:30,080
‫Wonder Lord fit grinning people validation data and then the quarterback

86
00:08:35,490 --> 00:08:43,350
‫so with each of this epoch I am also saving a model file for that epoch.

87
00:08:43,350 --> 00:08:50,640
‫So if we just go back to our directory we should have and model files.

88
00:08:50,640 --> 00:09:00,260
‫Here you can see we have more than less 0 1 model illustrator to model base than this for first epoch.

89
00:09:00,260 --> 00:09:04,120
‫Secondly both totally book and so on builder 10 people.

90
00:09:04,660 --> 00:09:13,120
‫If I would ever use the single file name such as more that than I did then I wouldn't be getting on

91
00:09:13,120 --> 00:09:18,670
‫the single file because of that e.g. bug that I was or what I could by the next book.

92
00:09:18,670 --> 00:09:27,290
‫When you so remember to use the variable names of each book while creating a modified for each epoch.

93
00:09:27,400 --> 00:09:34,530
‫Now I can load this files similar to the previous time.

94
00:09:34,700 --> 00:09:41,500
‫You just have to write it as thought model Lord Lord modern and the file which we want to load.

95
00:09:43,120 --> 00:09:50,860
‫So just to demonstrate that Let's delete the model and clear the session now.

96
00:09:50,920 --> 00:09:59,070
‫So suppose if I want a file of my ten people a model law.

97
00:10:02,320 --> 00:10:08,540
‫So this is the model I want to export.

98
00:10:09,320 --> 00:10:16,680
‫You can see if important that model so in future also if I am opening the department notebook after

99
00:10:16,700 --> 00:10:23,060
‫three or four days I can just write this model that gave us thought model dot load model and then the

100
00:10:23,070 --> 00:10:25,560
‫modelling to load that model.

101
00:10:25,610 --> 00:10:33,350
‫There is absolutely no need of creating compiling and creating the model once again.

102
00:10:33,680 --> 00:10:36,140
‫We can also use evaluate time.

103
00:10:36,380 --> 00:10:42,010
‫You can see this model object is working now.

104
00:10:42,320 --> 00:10:48,830
‫There is no need of saving the model at each epoch.

105
00:10:49,310 --> 00:10:56,910
‫If you are using the validation set during the training you can set the save best only equal to group

106
00:10:57,060 --> 00:10:58,970
‫by creating a checkpoint callback

107
00:11:01,660 --> 00:11:07,560
‫that will only save your model when it's performance on the validation set is best.

108
00:11:10,210 --> 00:11:20,410
‫So suppose all of this then epoch values we were getting the best validation is scored I suppose epoch

109
00:11:21,390 --> 00:11:27,040
‫then in the final fight we will be getting the model corresponding to epoch 8.

110
00:11:27,070 --> 00:11:36,000
‫There is no need to create a separate model for all this epoch where lose because generally we want

111
00:11:36,000 --> 00:11:39,130
‫a model corresponding to the best score on the

112
00:11:42,830 --> 00:11:53,410
‫so let us lead the model in creating this structure and here while creating the callback I am also setting

113
00:11:53,410 --> 00:12:02,720
‫the parameter value of save best only equal to crew and then I would be getting only a single model

114
00:12:03,100 --> 00:12:03,730
‫with the name.

115
00:12:03,790 --> 00:12:09,880
‫Best model does the model which is corresponding to the best value of validation is score.

116
00:12:12,610 --> 00:12:20,110
‫So let's just create this checkpoint and then we are creating the model.

117
00:12:20,170 --> 00:12:24,340
‫Again extreme epochs validation set and then the callbacks

118
00:12:36,020 --> 00:12:41,250
‫now to get the best model we can just import the best model that we have saved.

119
00:12:41,840 --> 00:12:49,640
‫So if you see in their directory also we have saved this best more than faith.

120
00:12:51,500 --> 00:13:00,110
‫We are just loading and using that more than do you and your performance on that site.

121
00:13:00,430 --> 00:13:07,070
‫No one of the best method to screen your model is to use a little scoping.

122
00:13:07,470 --> 00:13:14,280
‫What I'm referring to a list dropping is that you would run your model for a very large number of epoch

123
00:13:14,280 --> 00:13:15,240
‫values.

124
00:13:15,240 --> 00:13:25,880
‫Suppose here I am using 200 e-books and then I will keep an eye on my validation site score so suppose

125
00:13:26,390 --> 00:13:34,730
‫if after 60 e-books my validation set accuracy is not improving then I will stop the training at that

126
00:13:34,730 --> 00:13:40,860
‫point and I will be using the model with the best validation is quote so far.

127
00:13:41,630 --> 00:13:43,530
‫So this is an ideal situation.

128
00:13:43,550 --> 00:13:47,480
‫We don't have to worry about how many books we want to run.

129
00:13:47,480 --> 00:13:50,220
‫We just set a very high value of people.

130
00:13:50,300 --> 00:13:59,590
‫We monitor the validation site school and then select the best more than that we have got so far so

131
00:13:59,600 --> 00:14:07,490
‫to achieve that we will be needing an another callback which we generally call a list stopping callback

132
00:14:08,360 --> 00:14:17,530
‫and we will use this callback along with our normal callback of safe best only model.

133
00:14:18,200 --> 00:14:25,280
‫So in a list topping callback we have to provide the patients value new patients value is the number

134
00:14:25,280 --> 00:14:29,750
‫of epochs after which our screening will be interrupted.

135
00:14:30,200 --> 00:14:41,360
‫If there is no progress on the validation set score so suppose after 53 epochs we are not getting any

136
00:14:41,360 --> 00:14:50,820
‫improvement on our evaluation site discourse then get us will stop the screening at 63 blocks.

137
00:14:51,020 --> 00:14:56,280
‫So the difference between the 6 2 3 and 4 play 3 is then this is the patients.

138
00:14:56,370 --> 00:15:05,570
‫This the number of epochs get us will wait for any improvement in validation is score so earlier you

139
00:15:05,570 --> 00:15:08,170
‫saw value creating our functional model.

140
00:15:08,180 --> 00:15:14,900
‫We have we have to look at our valuation is score graph to check out whether our model is converging

141
00:15:14,900 --> 00:15:16,020
‫or not.

142
00:15:16,070 --> 00:15:18,410
‫Now we don't have to worry about that.

143
00:15:18,500 --> 00:15:27,380
‫We can use a list stopping along with other callbacks which will automatically save the best model that

144
00:15:27,380 --> 00:15:35,600
‫is available and it will also train our model for optimal amount of time needed to create that model

145
00:15:35,630 --> 00:15:37,920
‫good to its best accuracy score.

146
00:15:39,740 --> 00:15:42,830
‫So let's just run this.

147
00:15:42,860 --> 00:15:49,550
‫We are first creating this structure now along with barely stopping callback.

148
00:15:49,550 --> 00:15:53,020
‫We have to use the normal callbacks also to save the model.

149
00:15:54,380 --> 00:16:00,330
‫And here we are also using saved best on the barometer as well.

150
00:16:01,760 --> 00:16:09,020
‫So at the end of all this training we wouldn't be getting on the a single model file on which we would

151
00:16:09,020 --> 00:16:13,650
‫be getting the best validation service score.

152
00:16:13,670 --> 00:16:17,480
‫Now our second callback is a list stopping callback.

153
00:16:17,480 --> 00:16:27,470
‫Here you have to provide patients parameter for the number of e-books run this.

154
00:16:27,710 --> 00:16:29,210
‫Now we are preparing our more.

155
00:16:29,300 --> 00:16:34,040
‫We will be passing creating dataset epochs values.

156
00:16:34,040 --> 00:16:42,940
‫Remember to increase epoch values then the validation data and then callbacks.

157
00:16:43,070 --> 00:16:46,260
‫Again we are passing callbacks in the form of lists.

158
00:16:46,310 --> 00:16:52,840
‫We are first passing over a checkpoint callback and then we are passing over our list stopping callback.

159
00:16:52,980 --> 00:16:53,870
‫Just run this

160
00:17:21,250 --> 00:17:32,630
‫so their training has stopped after 87 epoch This means that there is no need to train it till 200 epoch

161
00:17:32,700 --> 00:17:34,820
‫values.

162
00:17:34,950 --> 00:17:41,970
‫Our model has already converged and there is no way to further decrease the validation loss.

163
00:17:41,970 --> 00:17:51,270
‫You can see the best value we are getting is that 70 70 book and it waited for 10 more epochs to get

164
00:17:51,710 --> 00:18:01,230
‫the better value then 0 1 3 2 and you can see after 10 in bulk we lose the value is still hovering over

165
00:18:01,350 --> 00:18:02,810
‫zero point three three.

166
00:18:02,830 --> 00:18:11,120
‫That's why it stopped at 80 70 pop value let's just look at our directory.

167
00:18:11,330 --> 00:18:18,440
‫We should have a model with file name on these top model yet.

168
00:18:18,500 --> 00:18:24,030
‫You can see us has already saved the best model.

169
00:18:24,770 --> 00:18:28,280
‫Here with the name Ollie's Top Model.

170
00:18:28,280 --> 00:18:30,020
‫So now the training has a stop.

171
00:18:30,080 --> 00:18:37,460
‫We can use this a list top model to predict and evaluate our future values.

172
00:18:37,550 --> 00:18:46,700
‫You can see the loss on tests that we are getting is 0 1 2 3 1 as compared to our previous lost values

173
00:18:46,760 --> 00:18:49,880
‫of zero point 4 3 7 8 and so on.

174
00:18:51,830 --> 00:18:59,120
‫So using only stop callback is a very good way to optimize performance of your model.

175
00:18:59,150 --> 00:19:03,970
‫You don't have to worry about the number of epochs.

176
00:19:05,330 --> 00:19:09,650
‫So let's have a quick recap of what we learned in this lecture.

177
00:19:09,660 --> 00:19:18,980
‫First we learn how to save and load our more than then we use callbacks to save our model.

178
00:19:19,100 --> 00:19:27,950
‫At EDC POC value then we learned about the parameter that is saved best only which will save the model

179
00:19:28,070 --> 00:19:36,860
‫for which we are getting the best accuracy score or lowest validation loss and after that we saw how

180
00:19:36,860 --> 00:19:46,830
‫to use only a stop callback to terminate the training if no progress on validation loss is occurring.

181
00:19:46,970 --> 00:19:48,890
‫So that's all for this lecture.

182
00:19:48,890 --> 00:19:49,310
‫Thank you.

