1
00:00:00,050 --> 00:00:06,440
In the section on data processing, we shall focus on resizing and rescaling.

2
00:00:06,470 --> 00:00:08,480
Firstly, we resizing.

3
00:00:08,510 --> 00:00:13,430
We'll start by explaining why we need to resize our data.

4
00:00:13,460 --> 00:00:16,970
So let's suppose that we have an input image.

5
00:00:16,970 --> 00:00:18,530
Or we have different inputs.

6
00:00:18,530 --> 00:00:22,400
Like we could have this one um of shape.

7
00:00:22,400 --> 00:00:25,580
Let's put out a shape uh just by ear.

8
00:00:25,580 --> 00:00:28,040
So let's say this is 256.

9
00:00:28,040 --> 00:00:29,810
So this could be 256.

10
00:00:29,810 --> 00:00:35,660
And then we have another, another input like this is 256 by 256 actually.

11
00:00:35,660 --> 00:00:37,670
So let's say this is 256.

12
00:00:38,000 --> 00:00:40,250
Um, by 256.

13
00:00:40,700 --> 00:00:43,700
Let's copy this and paste out here.

14
00:00:43,700 --> 00:00:47,720
And then we have another input which is let's, let's modify this.

15
00:00:47,720 --> 00:00:49,190
So smaller.

16
00:00:49,670 --> 00:00:50,600
There we go.

17
00:00:50,600 --> 00:00:52,250
We have this smaller image.

18
00:00:52,250 --> 00:00:56,840
And these two images make up our data set are part of our data set.

19
00:00:56,840 --> 00:00:58,910
So let's say this is 100.

20
00:00:58,910 --> 00:01:06,200
And uh 5150 by 150.

21
00:01:06,200 --> 00:01:12,800
So now we have um these two images which are part of our data set and which have two different shapes.

22
00:01:12,800 --> 00:01:23,300
Now, the point of us resizing is simply because our model, our model here will generally want to take

23
00:01:23,300 --> 00:01:27,050
in an input of the same shape.

24
00:01:27,050 --> 00:01:30,050
So we want to have an input of, um, a shape.

25
00:01:30,050 --> 00:01:34,340
Let's say, for example, 224 by 224.

26
00:01:34,340 --> 00:01:36,770
So 224 by 224.

27
00:01:36,770 --> 00:01:41,840
Now note that, um, if it's RGB, then you have 2 to 256 by 256 by three.

28
00:01:41,840 --> 00:01:45,650
And here you have two, 224 by 224 by three.

29
00:01:45,650 --> 00:01:51,560
So what we'll do is before passing in this input into our model, let's shift this this way.

30
00:01:51,800 --> 00:01:53,090
Let's take this this way.

31
00:01:53,090 --> 00:01:58,520
So before passing um this input into our model we will resize it.

32
00:01:58,520 --> 00:02:03,020
So we'll pass this into this resizing unit such that.

33
00:02:03,020 --> 00:02:11,720
Now we have um inputs of shape 224 by 224 before getting um, or before passing this input into our

34
00:02:11,720 --> 00:02:18,080
model, after resizing and making sure that we have the same shape for all the inputs, the next step

35
00:02:18,080 --> 00:02:21,140
will be to normalize our data.

36
00:02:21,140 --> 00:02:22,940
So let's say we have an input.

37
00:02:22,940 --> 00:02:26,870
We'll do x minus x mean.

38
00:02:27,350 --> 00:02:36,050
We'll call this x mean divided by x max minus x mean.

39
00:02:36,230 --> 00:02:44,600
Now in our case we know that the the minimum or x mean here is actually zero because the pixel values

40
00:02:44,600 --> 00:02:47,810
go from 0 to 255.

41
00:02:47,810 --> 00:02:55,190
So if x mean is zero then our x max is going to be 255.

42
00:02:55,190 --> 00:03:00,020
So just replacing here you see we have uh this is going to be equal x.

43
00:03:00,020 --> 00:03:03,800
Well x -0 is x divided by 255.

44
00:03:03,800 --> 00:03:08,120
So we normalize or we rescale our data in this way.

45
00:03:08,120 --> 00:03:12,680
One point we need to take note of is the fact that we are normalizing.

46
00:03:12,680 --> 00:03:21,230
Or we need to normalize our data before it being passed into our model, because we want to be able

47
00:03:21,230 --> 00:03:25,340
to restrain the range of our inputs.

48
00:03:25,340 --> 00:03:33,680
So we are going from a range of 0 to 55 to a range of 0 to 1.

49
00:03:33,890 --> 00:03:44,300
So restraining is um, or restraining our inputs in this way helps us now because our weights are those

50
00:03:44,300 --> 00:03:46,940
inputs will be multiplied by the weights.

51
00:03:46,940 --> 00:03:50,990
And if this range is quite large.

52
00:03:52,080 --> 00:04:00,120
We get a less stable training process as compared to when we multiplying weights by inputs whose range

53
00:04:00,120 --> 00:04:02,160
is, um, very small.

54
00:04:02,160 --> 00:04:08,880
So it's very important to normalize your data before passing it into the model.

55
00:04:08,880 --> 00:04:13,200
Um, apart from this normalization we could also have standardization.

56
00:04:13,200 --> 00:04:19,830
So first of all here we have normal normalization.

57
00:04:19,830 --> 00:04:20,700
There we go.

58
00:04:20,700 --> 00:04:22,260
We have normalization.

59
00:04:22,260 --> 00:04:25,470
And then we could also have standardization.

60
00:04:25,470 --> 00:04:31,860
So um in the case of standardization here the formula changes slightly.

61
00:04:31,860 --> 00:04:34,080
So we have standardization.

62
00:04:34,080 --> 00:04:44,190
And as we're saying we're going to have x minus a mean value divided by a standard deviation.

63
00:04:44,430 --> 00:04:51,960
Now this applies generally where we have this mean and standard deviation for a given data set.

64
00:04:51,960 --> 00:04:56,310
Like in the case of ImageNet the ImageNet data set which we are going to look at.

65
00:04:56,490 --> 00:05:04,980
Um in subsequent sections we have uh, we know this mean values for each and every channel.

66
00:05:04,980 --> 00:05:06,990
And we know also the standard deviations.

67
00:05:06,990 --> 00:05:14,220
So because we know this mean values um, of the pixels and the standard deviations, we could um standardize

68
00:05:14,220 --> 00:05:14,700
our data.

69
00:05:14,700 --> 00:05:18,450
So we could simply take x minus the mean value divided by the standard deviation.

70
00:05:18,450 --> 00:05:24,540
But in data sets like this current one where we don't have this already, we could just simply normalize.

71
00:05:24,540 --> 00:05:31,080
That is x minus x mean which in this case is zero divided by x max which is 255 -0.

72
00:05:31,080 --> 00:05:34,560
And so we have um this uh process instead.

73
00:05:34,560 --> 00:05:35,790
So that's it.

74
00:05:35,790 --> 00:05:37,590
We replace here.

75
00:05:37,590 --> 00:05:42,900
And now we have standardization or rather we have uh normalization.

76
00:05:42,900 --> 00:05:45,060
So yeah we have normalization.

77
00:05:45,060 --> 00:05:45,630
That's it.

78
00:05:45,630 --> 00:05:53,640
So uh, we, we resize and then we normalize or rescale our data, and then we pass this into our model.

79
00:05:53,640 --> 00:05:58,680
Diving back to the code was first of all start by defining the image size.

80
00:05:58,680 --> 00:06:02,430
So here we have image size set that to 224.

81
00:06:02,430 --> 00:06:08,250
And then we have our method which will uh the be the resize rescale method.

82
00:06:08,250 --> 00:06:12,270
And it takes in the image and its corresponding label.

83
00:06:12,270 --> 00:06:15,960
So here now what we're doing is we're simply going to resize.

84
00:06:15,960 --> 00:06:20,340
So we take or we make use of this resize method from TensorFlow image.

85
00:06:20,340 --> 00:06:24,570
Taking the image you could check um that out in the documentation.

86
00:06:24,870 --> 00:06:28,560
Um and then you specify the new size.

87
00:06:28,560 --> 00:06:32,640
So here we have m size by m size.

88
00:06:32,640 --> 00:06:33,360
So that's it.

89
00:06:33,360 --> 00:06:39,450
So whatever image you're going to have you're going to have now as output, um an image of shape 2224

90
00:06:39,450 --> 00:06:40,530
by 224.

91
00:06:40,530 --> 00:06:43,500
And then what we want to also do is label.

92
00:06:43,500 --> 00:06:45,480
Well we here we have the label.

93
00:06:45,480 --> 00:06:51,210
Now, as we've seen already, we just simply take whatever x and then divide by 255.

94
00:06:51,210 --> 00:06:56,820
So after resizing we'll divide by 255 and that'll be it.

95
00:06:56,820 --> 00:06:58,620
So let's run that again.

96
00:06:58,620 --> 00:07:01,620
We'll now modify our dataset.

97
00:07:01,620 --> 00:07:03,360
So here we have train.

98
00:07:03,360 --> 00:07:06,750
Let's call this train data set equal train.

99
00:07:07,020 --> 00:07:08,520
Um underscore dsx.

100
00:07:08,520 --> 00:07:15,450
And then we use the map method which is going to simply take in this um resize rescale method.

101
00:07:15,450 --> 00:07:20,580
So here we have resize rescale um and that's it.

102
00:07:20,580 --> 00:07:25,770
So now we have our new data set which is the original data set.

103
00:07:25,770 --> 00:07:27,930
But this time around we do resize rescale.

104
00:07:27,930 --> 00:07:31,260
So here we have missing one argument label.

105
00:07:31,740 --> 00:07:36,570
Um when we scroll back here we notice that this is actually a dictionary.

106
00:07:36,570 --> 00:07:41,400
So instead of taking this two separately we should just say we have inputs.

107
00:07:41,400 --> 00:07:45,030
And then now we have inputs inputs.

108
00:07:45,030 --> 00:07:46,560
And then we have image.

109
00:07:46,560 --> 00:07:48,240
So we pick that up.

110
00:07:48,240 --> 00:07:50,610
And then we also have input.

111
00:07:50,610 --> 00:07:53,010
And then here we have label.

112
00:07:53,010 --> 00:07:56,310
So let's um have this run that again.

113
00:07:56,310 --> 00:08:00,180
And this should work this time around we get another error.

114
00:08:00,570 --> 00:08:04,680
Um here we have input well inputs actually.

115
00:08:04,680 --> 00:08:06,810
So inputs run that again.

116
00:08:06,810 --> 00:08:07,740
There we go.

117
00:08:07,740 --> 00:08:15,480
That's what we have now we could do for image label in train the data set.

118
00:08:15,780 --> 00:08:17,520
Data set.

119
00:08:17,520 --> 00:08:19,440
Let's take a single element.

120
00:08:19,440 --> 00:08:22,980
And then let's print out the image and also print out the label.

121
00:08:23,670 --> 00:08:32,250
You could see now that we have this inputs where we have the shape or this um image shape to 24 by 224.

122
00:08:32,490 --> 00:08:34,440
Um, and then we have the output zero.

123
00:08:34,440 --> 00:08:35,580
So that's it.

124
00:08:35,580 --> 00:08:39,990
So we now have our data, but we just seen all zeros here.

125
00:08:39,990 --> 00:08:43,650
But let's do numpy unique.

126
00:08:43,650 --> 00:08:50,490
And then we pass in image and see and be sure that we actually have non-zero values in our image.

127
00:08:50,490 --> 00:08:51,510
You can see that we go from.

128
00:08:51,670 --> 00:08:54,760
Zero right up to 0.771.

129
00:08:54,760 --> 00:08:58,780
Which makes sense because our values are supposed to range between 0 and 1.

130
00:08:58,780 --> 00:08:59,950
And that's it for the section.

131
00:08:59,950 --> 00:09:04,390
In the next section, we'll dive into how the convolutional neural network works.
