‫Alrighty.
‫So now we've got our training split and validation split.
‫Our X values are the file paths to our images and our Y values.
‫The labels are boolean numpy 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
‫our images into numbers or at least create a function to do so for us.
‫So let's create a little heading for that.
‫We'll make it.
‫Preprocessing 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 TensorFlow.
‫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 preprocessing our images in the notebook, we might preprocessing them only when we need
‫to.
‫Because manipulating file paths is a lot easier than manipulating an image because it's working with
‫less data.
‫So because we've already got the file paths, I'm going to keep this theme for the rest of this project.
‫And I'm saying, might do.
‫We're going to do this.
‫We're going to start developing out some functionality for 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 going to 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 start thinking about in your workflows.
‫If you're thinking, Hey, I'm going to be preprocessing of 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 pre process.
‫Our images into tenses.
‫We're going to write a function which does a few things.
‫Now, this preprocessing 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 paths.
‫We want to use TensorFlow to read the file and save it to a variable.
‫We'll probably call that variable image.
‫Nice and simple.
‫Three 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.
‫Four.
‫What do we do next?
‫We need to resize 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
‫learning pipeline with images into a standardized size.
‫So we'll resize the image.
‫Uh, to be a shape of 224.
‫Now, I want you to have a 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 a resource here.
‫So TensorFlow.
‫Data loading.
‫Here we go.
‫So I'll leave this as an aside that you can start to read of how to load data into TensorFlow.
‫So this is a really good section to check out.
‫So TensorFlow 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 going to 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.
‫I look up load data.
‫And I 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.
‫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 a.
‫Right here.
‫Before we do,
‫let's say what importing an image looks like.
‫So I convert to numpy array.
‫Remember how I said tenses are very similar to dimensional numpy arrays or matrices?
‫So what we're going to see now, so we're importing just to map plot function in read which stands for
‫image read.
‫I'm going to save image to M read.
‫Let's get file names 42.
‫Remember, file names is just a list of file paths to our training images.
‫Which is up here.
‫Dog vision.
‫Training images.
‫And then we want to check image shape.
‫Okay.
‫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 width doesn't really matter.
‫I believe it's height, width, 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 obj a 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 in 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 numpy array, it should be.
‫There we go.
‫Values between zero and 255.
‫So if we go image dot max, maybe this will tell us.
‫255 and image men.
‫Zero.
‫There we go.
‫So red, green and blue pixel values between zero and 2.55.
‫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 numpy arrays.
‫So let's turn this into a tense and we can do that.
‫You can turn almost anything into a tensor by using TF Constant.
‫Now if we read the docstring creates a constant tensor from a tensor 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 what 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 TFA constant.
‫So the only difference here is that now we've got it in a tensor of shape to 353 and now it's shape
‫to 353.
‫We've indexed it to only show two.
‫But if you see this is an array numpy and this is a tensor.
‫The only difference here is that this tensor is intensive flow and now it's able to run on a CPU, so
‫a lot faster compute.
‫So our GPU will be able to find patterns in these numbers a lot faster than what our CPU, which is
‫on my current machine, my MacBook Pro, will be able 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 or blue between zero and 255.
‫We've seen what an image looks like in an umpire a 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 we were going to check out a write a function, but I think it's good to build some intuition
‫before we actually do write this function.
‫We'll 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.