1 00:00:00,510 --> 00:00:03,960 Did you give the challenge at the end of the last video ago. 2 00:00:03,990 --> 00:00:05,490 Here's the solution. 3 00:00:05,490 --> 00:00:09,640 The very first thing I want to do is import the model itself. 4 00:00:09,690 --> 00:00:16,910 So when I go to Caris the applications start Fiji 19 and import Fiji 19. 5 00:00:16,980 --> 00:00:28,770 So up here under my import statements I'll add exactly that from Kerry's dumped applications dot Fiji 6 00:00:29,070 --> 00:00:31,470 19 Fiji 16. 7 00:00:31,500 --> 00:00:40,170 It's just a different model that we're gonna go with 19 and we're going to import Fiji 19 but not only 8 00:00:40,170 --> 00:00:46,140 will we import Fiji 19 we're also gonna have to pre process the data for v g g 19. 9 00:00:46,290 --> 00:00:58,830 So we're going to import from Carrier stance applications thought Fiji 19 import pre process underscore 10 00:00:58,860 --> 00:00:59,830 input. 11 00:00:59,940 --> 00:01:03,240 This one is actually going to be different from this one. 12 00:01:03,240 --> 00:01:10,560 This was the first trick to solving this challenge and in order to not have a duplication with the names 13 00:01:10,680 --> 00:01:18,200 and in order to have a separate name for both of these and when to import this one as pre process underscore 14 00:01:18,340 --> 00:01:29,650 input on a score Fiji 19 out shift enter on this then I'll come down and I'm very very lazily going 15 00:01:29,650 --> 00:01:37,360 to copy the cell and copy this function and add another cell below pasted in. 16 00:01:37,630 --> 00:01:39,070 Change the name of it. 17 00:01:39,130 --> 00:01:47,620 Call it Vejjajiva 19 and then what I'll do is I'll change this target size because the Fiji 19 model 18 00:01:47,620 --> 00:01:50,680 assumes a different default resolution. 19 00:01:50,680 --> 00:01:53,750 Let's check what that is according to the documentation. 20 00:01:53,860 --> 00:01:59,670 And here we see that it's two hundred and twenty four by two hundred and twenty four. 21 00:01:59,740 --> 00:02:03,130 So those are the numbers I want to put in here. 22 00:02:03,130 --> 00:02:05,520 Make our lives easy. 23 00:02:06,280 --> 00:02:13,150 And then the other thing I have to do is I have to not pre process input which was the name for Inception 24 00:02:13,150 --> 00:02:20,150 resonates method I'm going to use pre process underscore input underscore Fiji 19. 25 00:02:20,170 --> 00:02:22,480 So this is what I want to use for this model. 26 00:02:22,870 --> 00:02:25,420 So let's shift enter on this. 27 00:02:25,420 --> 00:02:30,230 Then I'm gonna come down here and I want to load our model so check it out. 28 00:02:30,310 --> 00:02:39,690 Fiji 19 and then the scroll model is equal to Fiji 19 and which arguments rules. 29 00:02:40,090 --> 00:02:46,660 Looking at the documentation I can actually see that the default here is image net. 30 00:02:46,690 --> 00:02:51,000 So even if I leave this completely blank I'm going to get the image net weights. 31 00:02:51,250 --> 00:02:57,490 If I hit shift enter I'll see that it's downloading the data and it's downloading the weights. 32 00:02:57,490 --> 00:03:06,370 This don't H5 file and after it's done it's going to stop spinning here and I can go to the next cell 33 00:03:06,460 --> 00:03:09,060 and make a prediction. 34 00:03:09,130 --> 00:03:10,730 Let's try it out. 35 00:03:10,750 --> 00:03:22,020 Data is equal to format on a image and a score PDG 19 and I'm going to give it the file number three. 36 00:03:22,240 --> 00:03:34,620 Try that then we can write pred is equal to Fiji nineteen underscore model not predict parentheses data. 37 00:03:35,320 --> 00:03:37,930 So this will be our prediction. 38 00:03:37,930 --> 00:03:46,030 Now all we need to do is decode our predictions but we shouldn't actually use decode underscore predictions 39 00:03:46,030 --> 00:03:50,920 here because this function was associated with our resonant model. 40 00:03:50,920 --> 00:04:03,550 So once again we're gonna say from Kerry's thought applications thought Fiji 19 import decode predictions 41 00:04:04,930 --> 00:04:10,230 as decode underscore Fiji 19. 42 00:04:10,350 --> 00:04:16,930 We're going to give it a different name and when to import this function from this module here. 43 00:04:17,050 --> 00:04:25,630 That way we can be sure that the logic matches someone had shift enter on this scroll back down and 44 00:04:25,810 --> 00:04:33,120 I'm going to add one very quick line here to display our image with this play parentheses load underscore 45 00:04:33,130 --> 00:04:43,030 image parentheses file and a score three and then here I can decode and what will I decode. 46 00:04:43,150 --> 00:04:46,810 Well the prediction that we've gotten from our model. 47 00:04:47,230 --> 00:04:56,120 So let's take a very quick look and what we see here are some pretty interesting predictions right. 48 00:04:56,190 --> 00:05:02,220 The top prediction is actually submarine for this picture and that's worth about 17 percent. 49 00:05:02,280 --> 00:05:09,570 The second prediction breakwater with 12 and a half percent is actually what this truly is. 50 00:05:09,570 --> 00:05:18,000 But I can if I squint kind of see the submarine in this picture but it's very interesting that the error 51 00:05:18,270 --> 00:05:25,350 that a human would make looking at this kind of very quickly it's very similar to what the neural network 52 00:05:25,350 --> 00:05:30,680 is actually making here so I hope you were able to solve this challenge. 53 00:05:30,710 --> 00:05:38,270 The idea really was to practice using the documentation practice pre processing the data and making 54 00:05:38,270 --> 00:05:42,280 sure that you're comfortable using a different model as well. 55 00:05:42,410 --> 00:05:49,220 Because if you know how to use the e.g. 19 model and the inception resonant model then none of the others 56 00:05:49,430 --> 00:05:53,510 should really pose a problem as well. 57 00:05:53,510 --> 00:05:59,450 Now I've actually included a couple of images here where I found the models to struggle a little bit 58 00:05:59,960 --> 00:06:07,370 so I could tell you what those are so that you can see this for yourself and I'll just copy and paste 59 00:06:07,370 --> 00:06:19,220 this code here and I'll replace this with single quotes 0 6 feet dot j peg a hand if I take this here. 60 00:06:19,520 --> 00:06:23,750 Copy it pasted down here and hit shift enter. 61 00:06:23,810 --> 00:06:25,390 You'll see what I mean. 62 00:06:25,760 --> 00:06:33,260 So I've got a picture here of two hands holding some baby's feet and are e.g. 19 model predicts that 63 00:06:33,680 --> 00:06:41,890 this is a burrito with close to 36 percent accuracy we can take a look at what Inception Resnick thinks 64 00:06:41,890 --> 00:06:50,940 about this by coming up here adding the single quotes and adding 0 6 feet Doc j peg here. 65 00:06:50,950 --> 00:06:54,650 Let's see what we get in this case. 66 00:06:54,670 --> 00:06:58,210 There's a few more baby related things diaper. 67 00:06:58,210 --> 00:07:04,150 I totally see the diaper but I assume it's there and then it's picking up on this basket and this towel 68 00:07:04,150 --> 00:07:05,940 here which I think is very interesting. 69 00:07:06,100 --> 00:07:12,630 But one thing you'll notice is that the classifier is not really confident on any of these classifications. 70 00:07:12,640 --> 00:07:17,560 If you look at 9 percent 7 percent 5 percent accuracy it's not really sure. 71 00:07:17,590 --> 00:07:20,990 So it's kind of struggling with this one. 72 00:07:21,550 --> 00:07:24,160 Another really interesting one is actually the horse. 73 00:07:24,160 --> 00:07:33,880 So 0 for horse if I put that here and if I put that here as well it looks like so. 74 00:07:34,270 --> 00:07:44,200 So we've got some meadow and a white horse and the image classifier Inception is picking up on this 75 00:07:44,200 --> 00:07:51,970 kind of leaf here sorrel and it also seems to think that the animal in question here is a ram presumably 76 00:07:51,970 --> 00:07:57,590 because it's very very white and it's got these very pointy is at the top. 77 00:07:57,700 --> 00:08:05,560 So this is another good example of the classifier getting things not quite right or presumably so because 78 00:08:05,860 --> 00:08:12,670 I'm not really sure what kind of leaf is in the foreground here but let's see what Eugene 19 thinks 79 00:08:12,670 --> 00:08:13,540 of this. 80 00:08:13,540 --> 00:08:22,000 So 0 four horse 0 for horse let's go for it. 81 00:08:22,230 --> 00:08:26,310 Here we've got ram with 73 percent probability. 82 00:08:27,360 --> 00:08:29,660 So what's our takeaway from this. 83 00:08:29,670 --> 00:08:36,540 Well image classifiers even with the pre trained weights are not going to be 100 percent accurate but 84 00:08:36,900 --> 00:08:39,630 what's a good level of accuracy anyhow. 85 00:08:39,870 --> 00:08:46,260 What's kind of the state of the art level of accuracy on image classification. 86 00:08:46,260 --> 00:08:53,790 Well in 2017 Google actually released a really nice blog piece on its classifier that it used to train 87 00:08:53,790 --> 00:08:55,780 on image net's database. 88 00:08:56,100 --> 00:09:01,530 And this classifier was actually called Nas net which you've got under a crisis available and models 89 00:09:01,530 --> 00:09:02,260 here. 90 00:09:03,000 --> 00:09:10,350 And what Google did was a train this nascent model on approximately a million images and 60000 GP few 91 00:09:10,350 --> 00:09:14,340 hours and in the end on their validation data set. 92 00:09:14,340 --> 00:09:19,680 So when they were testing out their model they got about eighty two and a half percent accuracy for 93 00:09:19,680 --> 00:09:21,660 images that this model hasn't seen before. 94 00:09:21,660 --> 00:09:22,520 Right. 95 00:09:22,530 --> 00:09:24,910 So this is kind of the lay of the land. 96 00:09:24,970 --> 00:09:32,420 We've got very sophisticated models that are around 80 85 percent accurate for these kind of tasks. 97 00:09:32,430 --> 00:09:36,160 Now mind you the task here is actually very hard right. 98 00:09:36,180 --> 00:09:43,200 Because if you imagine we've been classifying things in our spam filter we've just two classes and in 99 00:09:43,200 --> 00:09:47,350 the next project we'll be classifying them on 10 different types of things. 100 00:09:47,460 --> 00:09:53,520 But in this case we've got thousands and thousands of different things that the image classifier is 101 00:09:53,520 --> 00:09:55,740 meant to detect in an image. 102 00:09:55,740 --> 00:09:57,770 And this is a much much harder job. 103 00:09:57,770 --> 00:10:05,100 Of course so I hope in this module you've got a good idea of how to access some pre train models and 104 00:10:05,100 --> 00:10:07,050 how to access their weights. 105 00:10:07,080 --> 00:10:13,290 You should have also got an idea of what it takes to really train a model to classify among thousands 106 00:10:13,290 --> 00:10:15,150 and thousands of different kinds of objects. 107 00:10:15,300 --> 00:10:22,160 And what kind of resources that would entail with that in mind pre train models really are a fantastic 108 00:10:22,160 --> 00:10:28,460 shortcut because it allows us to build on work that others have already done and we've covered in a 109 00:10:28,460 --> 00:10:35,590 bit of detail how specific the neural networks are in how they expect to receive their inputs. 110 00:10:35,630 --> 00:10:43,160 So it's very important to deliver a neural network the input data in a format that it understands and 111 00:10:43,160 --> 00:10:44,930 it expects to receive. 112 00:10:44,930 --> 00:10:50,300 And what we've seen is that different models expect to receive this kind of data in different ways. 113 00:10:50,300 --> 00:10:59,670 And we've also seen how image data is generally represented for a neural network and finally we've also 114 00:10:59,670 --> 00:11:03,590 learned a little bit about tensor flow and carers themselves. 115 00:11:03,600 --> 00:11:10,320 So for example this includes the graph intensive load that groups together the different calculations. 116 00:11:10,320 --> 00:11:15,420 And I think this really leaves a really good spot because we scratched the surface and now we can go 117 00:11:15,420 --> 00:11:22,230 one layer deeper pun intended in the next module we're going to be building our own image classifier 118 00:11:22,260 --> 00:11:23,490 from scratch. 119 00:11:23,490 --> 00:11:26,410 I'm already looking forward to seeing you there. 120 00:11:26,460 --> 00:11:27,000 Take care.