In the section on data processing, we shall focus on resizing and rescaling.
Firstly, we resizing.
We'll start by explaining why we need to resize our data.
So let's suppose that we have an input image.
Or we have different inputs.
Like we could have this one um of shape.
Let's put out a shape uh just by ear.
So let's say this is 256.
So this could be 256.
And then we have another, another input like this is 256 by 256 actually.
So let's say this is 256.
Um, by 256.
Let's copy this and paste out here.
And then we have another input which is let's, let's modify this.
So smaller.
There we go.
We have this smaller image.
And these two images make up our data set are part of our data set.
So let's say this is 100.
And uh 5150 by 150.
So now we have um these two images which are part of our data set and which have two different shapes.
Now, the point of us resizing is simply because our model, our model here will generally want to take
in an input of the same shape.
So we want to have an input of, um, a shape.
Let's say, for example, 224 by 224.
So 224 by 224.
Now note that, um, if it's RGB, then you have 2 to 256 by 256 by three.
And here you have two, 224 by 224 by three.
So what we'll do is before passing in this input into our model, let's shift this this way.
Let's take this this way.
So before passing um this input into our model we will resize it.
So we'll pass this into this resizing unit such that.
Now we have um inputs of shape 224 by 224 before getting um, or before passing this input into our
model, after resizing and making sure that we have the same shape for all the inputs, the next step
will be to normalize our data.
So let's say we have an input.
We'll do x minus x mean.
We'll call this x mean divided by x max minus x mean.
Now in our case we know that the the minimum or x mean here is actually zero because the pixel values
go from 0 to 255.
So if x mean is zero then our x max is going to be 255.
So just replacing here you see we have uh this is going to be equal x.
Well x -0 is x divided by 255.
So we normalize or we rescale our data in this way.
One point we need to take note of is the fact that we are normalizing.
Or we need to normalize our data before it being passed into our model, because we want to be able
to restrain the range of our inputs.
So we are going from a range of 0 to 55 to a range of 0 to 1.
So restraining is um, or restraining our inputs in this way helps us now because our weights are those
inputs will be multiplied by the weights.
And if this range is quite large.
We get a less stable training process as compared to when we multiplying weights by inputs whose range
is, um, very small.
So it's very important to normalize your data before passing it into the model.
Um, apart from this normalization we could also have standardization.
So first of all here we have normal normalization.
There we go.
We have normalization.
And then we could also have standardization.
So um in the case of standardization here the formula changes slightly.
So we have standardization.
And as we're saying we're going to have x minus a mean value divided by a standard deviation.
Now this applies generally where we have this mean and standard deviation for a given data set.
Like in the case of ImageNet the ImageNet data set which we are going to look at.
Um in subsequent sections we have uh, we know this mean values for each and every channel.
And we know also the standard deviations.
So because we know this mean values um, of the pixels and the standard deviations, we could um standardize
our data.
So we could simply take x minus the mean value divided by the standard deviation.
But in data sets like this current one where we don't have this already, we could just simply normalize.
That is x minus x mean which in this case is zero divided by x max which is 255 -0.
And so we have um this uh process instead.
So that's it.
We replace here.
And now we have standardization or rather we have uh normalization.
So yeah we have normalization.
That's it.
So uh, we, we resize and then we normalize or rescale our data, and then we pass this into our model.
Diving back to the code was first of all start by defining the image size.
So here we have image size set that to 224.
And then we have our method which will uh the be the resize rescale method.
And it takes in the image and its corresponding label.
So here now what we're doing is we're simply going to resize.
So we take or we make use of this resize method from TensorFlow image.
Taking the image you could check um that out in the documentation.
Um and then you specify the new size.
So here we have m size by m size.
So that's it.
So whatever image you're going to have you're going to have now as output, um an image of shape 2224
by 224.
And then what we want to also do is label.
Well we here we have the label.
Now, as we've seen already, we just simply take whatever x and then divide by 255.
So after resizing we'll divide by 255 and that'll be it.
So let's run that again.
We'll now modify our dataset.
So here we have train.
Let's call this train data set equal train.
Um underscore dsx.
And then we use the map method which is going to simply take in this um resize rescale method.
So here we have resize rescale um and that's it.
So now we have our new data set which is the original data set.
But this time around we do resize rescale.
So here we have missing one argument label.
Um when we scroll back here we notice that this is actually a dictionary.
So instead of taking this two separately we should just say we have inputs.
And then now we have inputs inputs.
And then we have image.
So we pick that up.
And then we also have input.
And then here we have label.
So let's um have this run that again.
And this should work this time around we get another error.
Um here we have input well inputs actually.
So inputs run that again.
There we go.
That's what we have now we could do for image label in train the data set.
Data set.
Let's take a single element.
And then let's print out the image and also print out the label.
You could see now that we have this inputs where we have the shape or this um image shape to 24 by 224.
Um, and then we have the output zero.
So that's it.
So we now have our data, but we just seen all zeros here.
But let's do numpy unique.
And then we pass in image and see and be sure that we actually have non-zero values in our image.
You can see that we go from.
Zero right up to 0.771.
Which makes sense because our values are supposed to range between 0 and 1.
And that's it for the section.
In the next section, we'll dive into how the convolutional neural network works.