1
00:00:00,110 --> 00:00:01,820
In the section on model training.

2
00:00:01,820 --> 00:00:10,220
We'll just simply start by, um, calling our fit method while specifying the train data set, the validation

3
00:00:10,220 --> 00:00:14,570
data set number of epochs, and the uh, set variables to be one.

4
00:00:14,570 --> 00:00:18,050
So let's run this and then see what we obtain.

5
00:00:18,200 --> 00:00:27,080
We get an error sequential um or input zero of layer sequential is incompatible with the layer expected

6
00:00:27,080 --> 00:00:30,410
um known by 224 by 224 by three.

7
00:00:30,410 --> 00:00:33,950
But the fine shape was 224 by two, 24 by three.

8
00:00:33,950 --> 00:00:41,900
So, um, this tells us that we our inputs are what we've gotten here in our train data set is unmatched.

9
00:00:41,900 --> 00:00:45,950
So let's get back and batch our data set.

10
00:00:45,950 --> 00:00:49,790
So here already we had carry out the splitting.

11
00:00:49,790 --> 00:00:51,890
And then we had our train data set.

12
00:00:51,890 --> 00:00:53,120
Then we had this mapping.

13
00:00:53,120 --> 00:00:58,190
So from here we could do batch uh and we specify the batch size.

14
00:00:58,640 --> 00:01:01,490
Here we specify the batch size.

15
00:01:01,490 --> 00:01:02,090
There we go.

16
00:01:02,090 --> 00:01:06,980
So let's include batch size right here we have batch size.

17
00:01:06,980 --> 00:01:09,080
And we say we want to have 32.

18
00:01:09,080 --> 00:01:10,730
So that's it for the train data set.

19
00:01:11,920 --> 00:01:16,270
Now let's repeat the same for the validation and then the testing.

20
00:01:16,270 --> 00:01:19,570
So well let's, let's do let's carry out shuffling.

21
00:01:19,960 --> 00:01:23,200
We have um before batching we'll shuffle.

22
00:01:23,200 --> 00:01:30,100
So we shuffle and then we specify uh buffer size of eight.

23
00:01:30,550 --> 00:01:31,990
Um reshuffle.

24
00:01:31,990 --> 00:01:34,300
Which reshuffle.

25
00:01:34,570 --> 00:01:38,650
Um each iteration set to true.

26
00:01:39,820 --> 00:01:40,840
There we go.

27
00:01:40,840 --> 00:01:42,430
We have the batch.

28
00:01:42,430 --> 00:01:44,350
And then we also prefetch.

29
00:01:44,350 --> 00:01:50,260
So here we have um prefetch prefetch.

30
00:01:50,260 --> 00:01:55,090
And then we have TensorFlow data um auto tune.

31
00:01:55,090 --> 00:01:57,970
So here we have auto tune okay.

32
00:01:57,970 --> 00:02:00,760
So that's it for the train data set.

33
00:02:00,760 --> 00:02:03,130
We could now repeat this for the validation.

34
00:02:03,130 --> 00:02:05,530
So let's have that paste that.

35
00:02:05,530 --> 00:02:08,860
Now we have Val take that off.

36
00:02:08,860 --> 00:02:10,450
And here we have test.

37
00:02:10,450 --> 00:02:15,070
So we have Val we have test.

38
00:02:15,070 --> 00:02:16,270
And there we go.

39
00:02:16,270 --> 00:02:19,480
So let's run that again and see what we obtain.

40
00:02:19,480 --> 00:02:21,550
So here we have batch size not defined.

41
00:02:21,550 --> 00:02:22,720
Let's run that again.

42
00:02:23,080 --> 00:02:24,220
And that should be fine.

43
00:02:24,220 --> 00:02:25,330
So we run this.

44
00:02:25,330 --> 00:02:29,560
And then you see that we have um an output now which has been bashed.

45
00:02:29,560 --> 00:02:32,050
So we should have the batch um dimension.

46
00:02:32,050 --> 00:02:33,340
So that's it right there.

47
00:02:33,340 --> 00:02:36,070
And you see we have 32 labels now.

48
00:02:36,490 --> 00:02:39,370
So let's get back and continue with the training.

49
00:02:39,370 --> 00:02:40,870
So let's run this again.

50
00:02:41,320 --> 00:02:43,060
Now this should be fine.

51
00:02:43,870 --> 00:02:47,740
We get in this other error logics and labels must have the same shape.

52
00:02:47,740 --> 00:02:53,800
So we received um this output batch by two instead of batch by one.

53
00:02:53,800 --> 00:02:59,620
And this makes sense because the way we created our outputs or if you look at our outputs we had here,

54
00:02:59,620 --> 00:03:05,710
if you look at this output labels, we have just for each and every sample, we have just one output.

55
00:03:05,710 --> 00:03:09,550
So um, it's not um shaped batch by two.

56
00:03:09,550 --> 00:03:15,040
So let's get back here um in our model and modify this.

57
00:03:15,040 --> 00:03:17,410
So instead of two we should have one.

58
00:03:17,410 --> 00:03:27,550
So if we are parasitized parasitized is zero um uninfected uninfected is one.

59
00:03:27,550 --> 00:03:31,360
So initially we were having two like this.

60
00:03:31,360 --> 00:03:37,930
We're supposing that the first we're supposing that we would have um if it's parasitized then we would

61
00:03:37,930 --> 00:03:39,760
have one and then zero.

62
00:03:39,760 --> 00:03:44,860
And then if it's uninfected, then we would have um, zero and then one.

63
00:03:44,860 --> 00:03:50,530
But we could simply just take all this off and just say if it's parasitized, we have zero.

64
00:03:50,530 --> 00:03:52,330
And then if it's uninfected we have one.

65
00:03:52,330 --> 00:03:56,110
So now we have an output of one unit instead of two.

66
00:03:56,110 --> 00:04:02,440
So let's take all this off, um, recompile our model and that should be fine.

67
00:04:03,260 --> 00:04:07,400
You could see now that our training has started, you could change the runtime, make sure you're using

68
00:04:07,400 --> 00:04:10,220
a GPU, which is quite slow because we're using the CPU.

69
00:04:10,220 --> 00:04:14,420
So if we take, um, the T4, that's it.

70
00:04:14,570 --> 00:04:16,430
We're going to have to restart the runtime.

71
00:04:16,430 --> 00:04:18,650
So let's go ahead and restart.

72
00:04:18,800 --> 00:04:26,180
Let's run this again and uh go ahead and restart the training.

73
00:04:26,180 --> 00:04:28,070
So let's have that.

74
00:04:28,310 --> 00:04:30,680
We recompile and we start the training.

75
00:04:30,680 --> 00:04:32,570
So we've restarted the training.

76
00:04:32,570 --> 00:04:37,520
And as you could see we have this loss and validation loss values.

77
00:04:37,520 --> 00:04:42,590
The training is quite slow with respect to how the loss values are dropping.

78
00:04:42,590 --> 00:04:47,420
And so we could get back here and make some um adjustments.

79
00:04:47,420 --> 00:04:51,800
Firstly we would use the ReLU activation instead of the sigmoid.

80
00:04:51,800 --> 00:04:54,260
So we'll replace all this with relus.

81
00:04:54,980 --> 00:04:57,410
Take this off and we have ReLU.

82
00:04:57,410 --> 00:05:04,100
And then also uh here in this final layer we are going to leave this at sigmoid because we want our

83
00:05:04,100 --> 00:05:06,530
outputs to, to lie between 0 and 1.

84
00:05:06,530 --> 00:05:09,770
Then we'll modify this kernel sizes.

85
00:05:10,040 --> 00:05:11,780
We'll go from 5 to 3.

86
00:05:12,050 --> 00:05:16,310
And then we shall include batch normalization.

87
00:05:16,310 --> 00:05:20,930
So just after the conv layer we have batch normalization.

88
00:05:20,930 --> 00:05:24,320
And then just after this let's add a comma.

89
00:05:24,350 --> 00:05:30,590
Just after this here we have batch normalization.

90
00:05:30,590 --> 00:05:31,430
There we go.

91
00:05:31,430 --> 00:05:33,260
We have batch normalization.

92
00:05:33,740 --> 00:05:37,040
And we just we just copy this and paste out here.

93
00:05:37,040 --> 00:05:41,270
So after the dense layer we would have batch norm take that off.

94
00:05:41,270 --> 00:05:43,190
After this dense we also have batch norm.

95
00:05:43,190 --> 00:05:52,070
So we including the batch normalization such that uh so that we could recenter and rescale the different

96
00:05:52,100 --> 00:05:57,650
um features we generating from our layers.

97
00:05:58,580 --> 00:06:04,160
So let's go ahead and stop the training and then recompile our model.

98
00:06:04,160 --> 00:06:05,540
So we have that.

99
00:06:05,540 --> 00:06:06,770
We recompile.

100
00:06:06,770 --> 00:06:13,250
And let's just copy this here and paste out here and run that again.

101
00:06:14,150 --> 00:06:21,380
Now just by looking at, um, the first two epochs, we see clearly that our model's loss now drops

102
00:06:21,380 --> 00:06:25,580
much faster as compared to, uh, what we had previously.

103
00:06:25,580 --> 00:06:27,140
So that's it.

104
00:06:27,140 --> 00:06:33,740
You see that, um, the batch normalization plays a great role in stabilizing our training and hence

105
00:06:33,740 --> 00:06:35,990
making it, uh, much faster.

106
00:06:35,990 --> 00:06:38,990
So we have this we will now add the metric.

107
00:06:38,990 --> 00:06:43,280
So metrics we will have binary accuracy.

108
00:06:43,280 --> 00:06:45,230
Binary accuracy metric.

109
00:06:45,470 --> 00:06:46,790
Uh make sure you import this.

110
00:06:46,790 --> 00:06:48,680
So we have binary accuracy.

111
00:06:48,680 --> 00:06:52,100
And the way accuracy works is quite simple.

112
00:06:52,100 --> 00:06:57,170
So here we have or let's suppose that we have 100 samples.

113
00:06:57,170 --> 00:06:59,240
So we have 100 samples.

114
00:06:59,240 --> 00:07:02,360
Or let's say we have one that um samples in our test set.

115
00:07:02,480 --> 00:07:12,800
Then if our model predicts correctly let's say 80 samples and doesn't correct or doesn't correctly predict

116
00:07:12,800 --> 00:07:19,970
the remaining 20, then our accuracy is going to be 0.8 or 80%.

117
00:07:19,970 --> 00:07:23,330
So it's just that simple and straightforward.

118
00:07:23,330 --> 00:07:30,650
So that's what we're going to have when we um include this binary accuracy metric right here.

119
00:07:30,650 --> 00:07:34,310
So you can see this is this is drop the vowel.

120
00:07:34,310 --> 00:07:36,380
Uh loss starts increasing slightly.

121
00:07:36,380 --> 00:07:40,730
Anyway let's just stop this and then we restart the training.

122
00:07:40,730 --> 00:07:42,350
So let's take this off.

123
00:07:42,800 --> 00:07:44,060
Um there we go.

124
00:07:44,060 --> 00:07:54,290
Let's, let's, um, recompile, let's recompile, and then we restart the training with the training

125
00:07:54,290 --> 00:07:55,040
are complete.

126
00:07:55,040 --> 00:07:58,400
You could see here our model loss which drops.

127
00:07:58,400 --> 00:08:06,560
And we also have this, uh, model accuracy which goes right up to, um, 0.95.

128
00:08:06,560 --> 00:08:11,660
So, um, our model now performs much better with the batch normalization.

129
00:08:11,660 --> 00:08:16,790
And we have this 95% accuracy, um, model.
