Oh Ronnie.
So now we've got our training split and validation split our X values are the file parts to our images
and our y values.
The labels are boolean num pi representations of the labels.
And so what we have to do now is since our labels are already in a numeric format we have to convert
how images into numbers or at least create a function to do so for us.
So let's create a little heading for that will make it pre processing images turning images into tenses
so we're kind of officially getting started on this step here and now when I say turning images into
tenses This is a common theme.
You'll have no matter what kind of data you're working on.
So even if it's not images if it's something like an audio file or it's a text passage you're still
going to have to turn it into tenses if you're working with tense flow and remember tenses are a numerical
representation kind of like a Matrix All right.
So what's one way we could do this again rather than pre processing our images in the notebook.
We might pre process them only when we need to because manipulating file past is a lot easier than manipulating
an image because it's working with less data.
So because we've already got the file parts we're going to keep this theme for the rest of this project
and I'm saying might do we're gonna do this we're gonna start developing out some functionality for
a steps in the project and what I mean by that is creating functions rather than just writing one line
of code and then running the cell.
The cell won't run because there's nothing there.
In the beginning when I first started out that's what I would do I would just run countless lines of
code in countless cells and then keep running it and then eventually even if I was way down below in
another part of the notebook I would have to rewrite the same code.
I'd already written somewhere up here so that's why we're gonna start creating functions so that we
can write code once it might take a little bit of time to begin with but we can reuse those functions
later on and that's what I want you to stop thinking about in your workflows if you're thinking hey
I'm going to be pretty processing the data here.
Maybe I might need that function that functionality later so I'll turn it into a function rather than
just a one off cell.
So let's do that to pretty process our images into tenses.
We're going to write a function which does a few things.
Now this pre processing function will be specific to images but the concept remains the same.
Whatever data you're working with you're probably going to have to turn it into some form of tensor.
So we want to take an image file path as input.
That's what we've got so far we've got image file parts.
We want to use tensor flow to read the file and save it to a variable We'll probably call that variable
image.
Nice and simple.
3 We want to turn our image so the image variable which will be a JPEG because that's the type of image
image file that we're dealing with in two tenses for which we do next we need to raise size the image.
So because all of our images are different sizes it's standard practice to usually resize all of your
images.
Image classification or some kind of deep pipeline with images into a standard eye size.
So we'll resize the image to be a shape of 2 24.
Now I want you to have to think about it without even having hands on experience with reshaping an image
why might it be important to have it now this size can be arbitrary.
But why might it be important to have images of a similar size when you're working with them.
Finally return the modified image now we've got five steps there for the function you might be thinking
wow how can I do that.
Well I want you to have a look at resources.
So you tend to flow data loading
it we go.
So I'll leave this as an aside that you can start to read of how to load data into intensive flow.
So this is a really good section to check out so tense of flow guide data.
I'll leave that in the resources section as an attachment if you want to check it out.
I just spend 10 minutes reading through here.
Maybe you could spend 10 minutes over the next couple of days even if you don't understand it.
Just starting to get some of the concepts together and now as for tutorials there should be another
one here.
I think load and pre process data.
So this is another valuable one we come here so this is what we're gonna be doing loading images.
My problem is trying to load images and I want to know how to turn them into tenses.
So I go to tutorials and look up load data and I'd look up how to load images and then you could read
through here.
So I'll make sure that I link these two resources.
And after you finish this video I want you to read through them for about 10 minutes each so let's go
back and let's build this function out here.
But before we do I just want to give you a demonstration of what an image actually looks like if we
were to read it in and what a tensor looks like.
So let's convert an image to an umpire right.
Right here before we do
let's say what importing an image looks like so convert to an umpire right.
Remember how I said tenses are very similar to multi-dimensional no high rise or matrices.
So what we're gonna say now.
So we're importing just to map what label function m raid which stands for image raid.
We're gonna save image to m raid let's get file names 42 remember file names is just a list of file
parts to our training images which is up here dog vision training images and then we want to check image
dot shape
OK so this is our image here.
This is height width.
Actually I always get confused but that's why we kind of reshape them to be like a square image so that
height and weight doesn't really matter.
I believe it's height with color channel and what I mean by color channel is red green and blue pixels.
So if we go here what is a color.
Channel
Channel big color sample so this is what an image is made up of red green and blue colors.
I'll let you dive a little bit more into that yourself but you're just going to have to trust me that
each pixel and an image here is some combination of red green and blue values.
And they range from 0 to 255.
So if we have a look at our image which is a number higher Ray it should be.
There we go.
Values between 0 and 255 so if we go image dot Max maybe this will tell us 255 and image dot men
0.
There we go.
So red green and blue pixel values between 0 and 2 5 5.
That is literally what our image is now.
It's in an umpire right.
At the moment I remember how I said tenses are very similar to num high rise.
So let's turn this into a tense and we can do that.
You can turn almost anything into a tensor by using T F constant.
Now if we read the doctoring creates a constant tensor from a tense a like object beautiful you can
read a little bit more into that.
But remember our motto if in doubt run the code.
So that's we're going to practice.
Let's see what this does.
We've got the exact same values actually let's demonstrate this we want image and maybe only up to two.
Same with TAF constant.
So the only difference here is that now we've got it in a tensor of shape to three fifty three and now
its shape to 353.
We've indexed it to only show two.
But if you see this is an array number why this is a tensor.
The only difference here is that this tensor is intensive low and now it's able to run on a GP.
So a lot faster compute.
So GPA will be out to find patterns in these numbers a lot faster than what LCP you which is on my current
machine my MacBook Pro will be out to find patterns in these let's go here turn image into a tensor.
So now we've seen a little bit of the basics behind what an image is composed of what kind of data pixel
values red green on blue between 0 2 5 5.
We've seen what an image looks like in a non pi array and we've seen what an image looks like in a tensor.
Let's finally get to our function which has to do these five steps.
So what we might do to save this video from getting too long.
I know I said out we were going to check out a write a function but I think it's good to build some
intuition before we actually do right.
This function will build this function in the next video so in the meantime try and put one of your
own images here.
You can choose any file name number.
And then just have a play around with the different values and try turning it into a tensor.