1 00:00:00,300 --> 00:00:00,870 Oh Ronnie. 2 00:00:01,110 --> 00:00:10,080 So now we've got our training split and validation split our X values are the file parts to our images 3 00:00:10,650 --> 00:00:11,700 and our y values. 4 00:00:11,700 --> 00:00:16,420 The labels are boolean num pi representations of the labels. 5 00:00:16,740 --> 00:00:23,710 And so what we have to do now is since our labels are already in a numeric format we have to convert 6 00:00:23,710 --> 00:00:28,500 how images into numbers or at least create a function to do so for us. 7 00:00:29,010 --> 00:00:41,030 So let's create a little heading for that will make it pre processing images turning images into tenses 8 00:00:42,630 --> 00:00:48,600 so we're kind of officially getting started on this step here and now when I say turning images into 9 00:00:48,600 --> 00:00:51,080 tenses This is a common theme. 10 00:00:51,630 --> 00:00:54,600 You'll have no matter what kind of data you're working on. 11 00:00:54,600 --> 00:01:01,170 So even if it's not images if it's something like an audio file or it's a text passage you're still 12 00:01:01,170 --> 00:01:06,840 going to have to turn it into tenses if you're working with tense flow and remember tenses are a numerical 13 00:01:06,930 --> 00:01:10,750 representation kind of like a Matrix All right. 14 00:01:10,950 --> 00:01:16,460 So what's one way we could do this again rather than pre processing our images in the notebook. 15 00:01:16,470 --> 00:01:25,560 We might pre process them only when we need to because manipulating file past is a lot easier than manipulating 16 00:01:25,560 --> 00:01:28,190 an image because it's working with less data. 17 00:01:28,280 --> 00:01:32,640 So because we've already got the file parts we're going to keep this theme for the rest of this project 18 00:01:32,760 --> 00:01:39,560 and I'm saying might do we're gonna do this we're gonna start developing out some functionality for 19 00:01:39,570 --> 00:01:44,910 a steps in the project and what I mean by that is creating functions rather than just writing one line 20 00:01:44,910 --> 00:01:47,250 of code and then running the cell. 21 00:01:47,370 --> 00:01:49,520 The cell won't run because there's nothing there. 22 00:01:49,710 --> 00:01:54,210 In the beginning when I first started out that's what I would do I would just run countless lines of 23 00:01:54,210 --> 00:01:59,940 code in countless cells and then keep running it and then eventually even if I was way down below in 24 00:02:00,390 --> 00:02:03,570 another part of the notebook I would have to rewrite the same code. 25 00:02:03,690 --> 00:02:09,090 I'd already written somewhere up here so that's why we're gonna start creating functions so that we 26 00:02:09,090 --> 00:02:15,210 can write code once it might take a little bit of time to begin with but we can reuse those functions 27 00:02:15,210 --> 00:02:19,110 later on and that's what I want you to stop thinking about in your workflows if you're thinking hey 28 00:02:19,800 --> 00:02:22,200 I'm going to be pretty processing the data here. 29 00:02:22,200 --> 00:02:27,240 Maybe I might need that function that functionality later so I'll turn it into a function rather than 30 00:02:27,240 --> 00:02:28,800 just a one off cell. 31 00:02:29,010 --> 00:02:37,300 So let's do that to pretty process our images into tenses. 32 00:02:37,300 --> 00:02:43,840 We're going to write a function which does a few things. 33 00:02:43,930 --> 00:02:50,020 Now this pre processing function will be specific to images but the concept remains the same. 34 00:02:50,230 --> 00:02:55,030 Whatever data you're working with you're probably going to have to turn it into some form of tensor. 35 00:02:55,030 --> 00:02:59,820 So we want to take an image file path as input. 36 00:02:59,830 --> 00:03:02,760 That's what we've got so far we've got image file parts. 37 00:03:02,890 --> 00:03:15,200 We want to use tensor flow to read the file and save it to a variable We'll probably call that variable 38 00:03:15,300 --> 00:03:15,940 image. 39 00:03:16,010 --> 00:03:17,530 Nice and simple. 40 00:03:17,870 --> 00:03:27,620 3 We want to turn our image so the image variable which will be a JPEG because that's the type of image 41 00:03:27,740 --> 00:03:34,930 image file that we're dealing with in two tenses for which we do next we need to raise size the image. 42 00:03:35,000 --> 00:03:41,600 So because all of our images are different sizes it's standard practice to usually resize all of your 43 00:03:41,600 --> 00:03:42,110 images. 44 00:03:42,110 --> 00:03:48,340 Image classification or some kind of deep pipeline with images into a standard eye size. 45 00:03:48,530 --> 00:03:55,820 So we'll resize the image to be a shape of 2 24. 46 00:03:55,820 --> 00:04:00,530 Now I want you to have to think about it without even having hands on experience with reshaping an image 47 00:04:00,530 --> 00:04:05,360 why might it be important to have it now this size can be arbitrary. 48 00:04:05,360 --> 00:04:10,610 But why might it be important to have images of a similar size when you're working with them. 49 00:04:10,670 --> 00:04:21,090 Finally return the modified image now we've got five steps there for the function you might be thinking 50 00:04:21,090 --> 00:04:22,600 wow how can I do that. 51 00:04:22,650 --> 00:04:24,830 Well I want you to have a look at resources. 52 00:04:24,880 --> 00:04:28,800 So you tend to flow data loading 53 00:04:31,990 --> 00:04:32,610 it we go. 54 00:04:33,110 --> 00:04:40,920 So I'll leave this as an aside that you can start to read of how to load data into intensive flow. 55 00:04:40,980 --> 00:04:45,180 So this is a really good section to check out so tense of flow guide data. 56 00:04:45,210 --> 00:04:48,660 I'll leave that in the resources section as an attachment if you want to check it out. 57 00:04:48,660 --> 00:04:51,200 I just spend 10 minutes reading through here. 58 00:04:51,300 --> 00:04:55,620 Maybe you could spend 10 minutes over the next couple of days even if you don't understand it. 59 00:04:55,620 --> 00:05:02,720 Just starting to get some of the concepts together and now as for tutorials there should be another 60 00:05:02,720 --> 00:05:03,250 one here. 61 00:05:04,450 --> 00:05:06,370 I think load and pre process data. 62 00:05:07,330 --> 00:05:14,580 So this is another valuable one we come here so this is what we're gonna be doing loading images. 63 00:05:14,580 --> 00:05:18,650 My problem is trying to load images and I want to know how to turn them into tenses. 64 00:05:18,780 --> 00:05:26,400 So I go to tutorials and look up load data and I'd look up how to load images and then you could read 65 00:05:26,400 --> 00:05:27,030 through here. 66 00:05:29,390 --> 00:05:32,150 So I'll make sure that I link these two resources. 67 00:05:32,150 --> 00:05:37,970 And after you finish this video I want you to read through them for about 10 minutes each so let's go 68 00:05:37,970 --> 00:05:41,780 back and let's build this function out here. 69 00:05:41,780 --> 00:05:47,930 But before we do I just want to give you a demonstration of what an image actually looks like if we 70 00:05:47,930 --> 00:05:51,200 were to read it in and what a tensor looks like. 71 00:05:51,200 --> 00:05:55,230 So let's convert an image to an umpire right. 72 00:05:58,500 --> 00:06:00,480 Right here before we do 73 00:06:04,050 --> 00:06:12,190 let's say what importing an image looks like so convert to an umpire right. 74 00:06:12,200 --> 00:06:19,540 Remember how I said tenses are very similar to multi-dimensional no high rise or matrices. 75 00:06:19,710 --> 00:06:20,560 So what we're gonna say now. 76 00:06:20,590 --> 00:06:25,870 So we're importing just to map what label function m raid which stands for image raid. 77 00:06:25,870 --> 00:06:34,060 We're gonna save image to m raid let's get file names 42 remember file names is just a list of file 78 00:06:34,060 --> 00:06:47,510 parts to our training images which is up here dog vision training images and then we want to check image 79 00:06:47,520 --> 00:06:48,000 dot shape 80 00:06:51,420 --> 00:06:53,760 OK so this is our image here. 81 00:06:53,760 --> 00:06:55,650 This is height width. 82 00:06:55,650 --> 00:07:01,770 Actually I always get confused but that's why we kind of reshape them to be like a square image so that 83 00:07:01,770 --> 00:07:03,450 height and weight doesn't really matter. 84 00:07:03,450 --> 00:07:10,320 I believe it's height with color channel and what I mean by color channel is red green and blue pixels. 85 00:07:10,380 --> 00:07:13,560 So if we go here what is a color. 86 00:07:13,560 --> 00:07:13,980 Channel 87 00:07:18,280 --> 00:07:25,400 Channel big color sample so this is what an image is made up of red green and blue colors. 88 00:07:25,400 --> 00:07:29,330 I'll let you dive a little bit more into that yourself but you're just going to have to trust me that 89 00:07:29,810 --> 00:07:35,660 each pixel and an image here is some combination of red green and blue values. 90 00:07:35,660 --> 00:07:39,680 And they range from 0 to 255. 91 00:07:39,890 --> 00:07:47,840 So if we have a look at our image which is a number higher Ray it should be. 92 00:07:47,920 --> 00:07:48,730 There we go. 93 00:07:48,760 --> 00:08:01,860 Values between 0 and 255 so if we go image dot Max maybe this will tell us 255 and image dot men 94 00:08:05,030 --> 00:08:05,880 0. 95 00:08:05,880 --> 00:08:06,540 There we go. 96 00:08:06,540 --> 00:08:09,620 So red green and blue pixel values between 0 and 2 5 5. 97 00:08:09,630 --> 00:08:15,000 That is literally what our image is now. 98 00:08:15,020 --> 00:08:16,310 It's in an umpire right. 99 00:08:16,310 --> 00:08:21,160 At the moment I remember how I said tenses are very similar to num high rise. 100 00:08:21,230 --> 00:08:24,180 So let's turn this into a tense and we can do that. 101 00:08:24,260 --> 00:08:28,880 You can turn almost anything into a tensor by using T F constant. 102 00:08:28,880 --> 00:08:36,910 Now if we read the doctoring creates a constant tensor from a tense a like object beautiful you can 103 00:08:36,910 --> 00:08:38,070 read a little bit more into that. 104 00:08:38,080 --> 00:08:40,750 But remember our motto if in doubt run the code. 105 00:08:40,750 --> 00:08:41,980 So that's we're going to practice. 106 00:08:42,520 --> 00:08:45,250 Let's see what this does. 107 00:08:45,280 --> 00:08:57,490 We've got the exact same values actually let's demonstrate this we want image and maybe only up to two. 108 00:08:57,550 --> 00:08:59,380 Same with TAF constant. 109 00:09:00,130 --> 00:09:08,050 So the only difference here is that now we've got it in a tensor of shape to three fifty three and now 110 00:09:08,080 --> 00:09:09,850 its shape to 353. 111 00:09:09,880 --> 00:09:12,070 We've indexed it to only show two. 112 00:09:12,160 --> 00:09:18,200 But if you see this is an array number why this is a tensor. 113 00:09:18,430 --> 00:09:25,000 The only difference here is that this tensor is intensive low and now it's able to run on a GP. 114 00:09:25,030 --> 00:09:26,280 So a lot faster compute. 115 00:09:26,290 --> 00:09:32,920 So GPA will be out to find patterns in these numbers a lot faster than what LCP you which is on my current 116 00:09:32,920 --> 00:09:40,820 machine my MacBook Pro will be out to find patterns in these let's go here turn image into a tensor. 117 00:09:41,270 --> 00:09:47,300 So now we've seen a little bit of the basics behind what an image is composed of what kind of data pixel 118 00:09:47,300 --> 00:09:50,300 values red green on blue between 0 2 5 5. 119 00:09:50,300 --> 00:09:56,010 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. 120 00:09:56,060 --> 00:10:02,180 Let's finally get to our function which has to do these five steps. 121 00:10:02,180 --> 00:10:05,340 So what we might do to save this video from getting too long. 122 00:10:05,540 --> 00:10:09,890 I know I said out we were going to check out a write a function but I think it's good to build some 123 00:10:09,890 --> 00:10:11,680 intuition before we actually do right. 124 00:10:11,690 --> 00:10:17,230 This function will build this function in the next video so in the meantime try and put one of your 125 00:10:17,230 --> 00:10:18,830 own images here. 126 00:10:19,000 --> 00:10:20,650 You can choose any file name number. 127 00:10:20,710 --> 00:10:24,940 And then just have a play around with the different values and try turning it into a tensor.