1
00:00:08,140 --> 00:00:14,260
Hey guys this is Caleb with slopes dot com and in this video we're going to dive right into adding our

2
00:00:14,260 --> 00:00:15,580
core a male model.

3
00:00:15,580 --> 00:00:20,800
We're going to pass an image into it and actually use machine learning to make a prediction of what

4
00:00:20,800 --> 00:00:22,710
it thinks that it's seeing in the image.

5
00:00:22,720 --> 00:00:24,060
Very very cool.

6
00:00:24,070 --> 00:00:30,370
In the last video we left off with this we have our camera view we have our nice labels and our views

7
00:00:30,400 --> 00:00:36,190
and when we tap the screen it takes a photo of what it sees and it saves it to the image of you.

8
00:00:36,370 --> 00:00:41,310
We're going to use that in just a moment to pass into our core a male model.

9
00:00:41,320 --> 00:00:47,320
OK so to begin we're actually going to pull open Safari and we're going to go ahead and head to the

10
00:00:47,350 --> 00:00:49,510
core M-L site from Apple.

11
00:00:49,510 --> 00:00:54,550
If you don't remember it's app developers Apple dot com slash machine learning.

12
00:00:54,880 --> 00:01:01,900
Now if you scroll way down to the bottom there is a section called working with models and basically

13
00:01:01,900 --> 00:01:09,220
Apple have provided quite a few different machine learning models that work with core M-L the one we're

14
00:01:09,220 --> 00:01:11,580
going to use is called squeeze net.

15
00:01:11,770 --> 00:01:18,580
And what it does is it detects the dominant objects present in an image from a set of 1000 categories

16
00:01:18,970 --> 00:01:27,160
like trees animals food vehicles people and more but with an overall footprint of 4.7 megabytes it's

17
00:01:27,160 --> 00:01:28,500
really really small.

18
00:01:28,600 --> 00:01:33,160
And if you actually look at some of these other core and L models you'll see they're pretty big 100

19
00:01:33,160 --> 00:01:35,230
to megabytes 94 megabytes.

20
00:01:35,240 --> 00:01:37,720
Five hundred fifty three megabytes.

21
00:01:37,720 --> 00:01:42,490
So this one is just way more efficient and way smaller.

22
00:01:42,490 --> 00:01:46,170
I mean that's just good for our app it will make the app size much smaller in the end.

23
00:01:46,210 --> 00:01:51,700
So to get that model go ahead and just click download core Armel model and it'll save to your downloads

24
00:01:51,700 --> 00:01:53,260
which you can see right here.

25
00:01:58,620 --> 00:02:01,830
Which you can see right here and it is called squeeze net.

26
00:02:01,980 --> 00:02:06,600
M-L model that of course stands for machine learning model.

27
00:02:06,600 --> 00:02:11,760
Now what we need to do is open our X code project and add this file into the project so go ahead and

28
00:02:11,760 --> 00:02:13,880
pull open your ex code project.

29
00:02:14,040 --> 00:02:19,780
And I'm actually going to just drag this from safari and drop it right into my project.

30
00:02:19,800 --> 00:02:27,220
Now of course copy items if needed create groups and make sure that the target vision app has been selected.

31
00:02:27,690 --> 00:02:31,770
Click Finish and we're going to go check out what is in this M-L model.

32
00:02:32,250 --> 00:02:36,350
So click on that and you'll notice here it says that it is a machine learning model.

33
00:02:36,420 --> 00:02:39,270
It's of type and neural network classifier.

34
00:02:39,270 --> 00:02:42,530
So now you understand how the structure is is working.

35
00:02:42,750 --> 00:02:47,620
And it gives you a nice description and also references the inputs.

36
00:02:47,640 --> 00:02:49,110
OK this is important to know.

37
00:02:49,350 --> 00:02:58,150
So we input an image and you see right here that it is BGR 6:58 and you can't see it but that's 6:58.

38
00:02:58,260 --> 00:03:05,650
That means that the input image that it can classify is 227 pixels by 227 pixels.

39
00:03:05,880 --> 00:03:08,310
The outputs are what we get at the end.

40
00:03:08,410 --> 00:03:13,560
OK so we get a class label probs which is the probability of each category.

41
00:03:13,830 --> 00:03:18,060
And we also get the class label which is the most likely image category.

42
00:03:18,060 --> 00:03:23,070
So it will tell us what it thinks it is and the probability that it thinks it's correct.

43
00:03:23,100 --> 00:03:28,470
If you notice here we have squeezed net and it says that it is a swift generated source.

44
00:03:28,470 --> 00:03:35,310
That means that squeeze net is accessible to us as as a model like we can use it just like we can use

45
00:03:35,340 --> 00:03:36,660
any other class.

46
00:03:36,750 --> 00:03:39,490
And let's click this little arrow here so I can show you that.

47
00:03:39,510 --> 00:03:40,160
Check it out.

48
00:03:40,260 --> 00:03:47,430
So it is a Class A swift class it's ready for us to use with squeeze net input right here squeeze net

49
00:03:47,460 --> 00:03:49,200
output can scroll down.

50
00:03:49,200 --> 00:03:55,720
We can actually see the whole squeeze NET class right here it's very cool and all available for us.

51
00:03:55,740 --> 00:03:59,150
That way you can take a look at this more and you can kind of dive in deeper if you want to.

52
00:03:59,160 --> 00:04:04,440
But for now we're just going to go ahead and we're going to add this into the resources folder and go

53
00:04:04,440 --> 00:04:05,770
to camera AVC.

54
00:04:05,790 --> 00:04:06,730
Let's use it.

55
00:04:06,780 --> 00:04:08,300
Let's see what it can do.

56
00:04:08,820 --> 00:04:12,650
So to begin we're going to go ahead and we're going to actually import two frameworks.

57
00:04:12,660 --> 00:04:17,370
First we're going to import core M-L and last we're going to import vision.

58
00:04:17,490 --> 00:04:24,810
OK these are both part of the core M-L package Carmel l handles just kind of your basic overarching

59
00:04:24,870 --> 00:04:32,700
all of the machine learning stuff and vision specifically handles things like face recognition and object

60
00:04:32,700 --> 00:04:33,370
recognition.

61
00:04:33,390 --> 00:04:37,670
We already talked about that and one of the first videos but just just a quick reminder.

62
00:04:37,680 --> 00:04:43,680
All right so now we get to actually use this machine learning model we've dragged in Squeeze net and

63
00:04:43,680 --> 00:04:49,140
to do that go ahead and scroll down and where we created the photo data we're actually going to use

64
00:04:49,140 --> 00:04:54,650
that same photo data and pass it into our core M-L model squeeze net.

65
00:04:54,720 --> 00:05:00,710
So to do that go ahead and go beneath the photo data and we're going to use a do try catch block.

66
00:05:00,740 --> 00:05:01,190
OK.

67
00:05:01,440 --> 00:05:04,820
We need to be able to catch any errors that are thrown.

68
00:05:05,070 --> 00:05:10,890
And using vision can throw errors and so we're going to set it up so that it can handle that and not

69
00:05:10,890 --> 00:05:12,330
cause a crash in our application.

70
00:05:12,480 --> 00:05:13,920
So go ahead and type do.

71
00:05:14,400 --> 00:05:17,600
And we're going to just set up the catch block as well while we're at it.

72
00:05:18,000 --> 00:05:18,600
Perfect.

73
00:05:18,600 --> 00:05:22,270
And this is where we're going to handle errors in just a moment.

74
00:05:22,410 --> 00:05:25,410
But inside the do block we're going to type let.

75
00:05:25,530 --> 00:05:31,120
Model equals try v and core I'm L model k.

76
00:05:31,140 --> 00:05:35,880
Now we're going to do a parentheses and we're going to pass in an L model.

77
00:05:35,880 --> 00:05:42,510
Now if you remember squeeze net is an M L model so what we can do is we can just pass in Squeeze net

78
00:05:42,930 --> 00:05:48,070
we can instantiate it and if we put a period we can pull out the male model.

79
00:05:48,120 --> 00:05:55,510
If you go to look at this this class you can see that there is a variable here that is for an N L model

80
00:05:55,510 --> 00:05:59,920
so we can pull that out and we can use that as a vision Cornell model.

81
00:05:59,970 --> 00:06:00,780
Really really cool.

82
00:06:00,780 --> 00:06:07,020
So basically we're using squeeze net but we're passing it through vision cause vision has a lot of really

83
00:06:07,020 --> 00:06:10,060
cool stuff for identifying things and images.

84
00:06:10,920 --> 00:06:16,200
And of course we're using try because Wii and core AML model can throw errors and you'll notice in a

85
00:06:16,200 --> 00:06:19,950
while little say that we're having some errors because we're not properly handling them in our catch

86
00:06:19,950 --> 00:06:20,250
block.

87
00:06:20,250 --> 00:06:21,390
But we will.

88
00:06:21,390 --> 00:06:23,320
So we now have a model.

89
00:06:23,340 --> 00:06:24,230
This is good.

90
00:06:24,240 --> 00:06:30,450
The models like our brain and now we need to make a request which is kind of like a thought case where

91
00:06:30,750 --> 00:06:32,770
we're allowing our brain to have a thought.

92
00:06:32,790 --> 00:06:37,290
And then it's going to do something with that thought later so after we've created our model go ahead

93
00:06:37,290 --> 00:06:43,350
and type let request and this is where we're going to use a V.N. core M-L request.

94
00:06:43,400 --> 00:06:45,150
Gates right there ready for you.

95
00:06:45,270 --> 00:06:48,090
Now if you put a parentheses you can see that there are two options.

96
00:06:48,100 --> 00:06:52,710
There's one with a model and one with the completion handler and model.

97
00:06:52,710 --> 00:06:59,340
We're going to use that one because our completion handler will be where we will handle what happens

98
00:06:59,340 --> 00:07:01,970
when we get a response back from this request.

99
00:07:02,070 --> 00:07:02,640
OK.

100
00:07:02,640 --> 00:07:05,960
Now our model of course is going to be our model.

101
00:07:06,120 --> 00:07:12,200
And now this completion handler This is where we're going to call a function we will right in a moment.

102
00:07:12,210 --> 00:07:18,340
So for now I'm going to go ahead and write that function but I'm not going to use it yet.

103
00:07:18,360 --> 00:07:25,620
So up here in our camera class we need to write that function and we're going to put it beneath did

104
00:07:25,620 --> 00:07:26,920
tap camera view.

105
00:07:27,000 --> 00:07:32,680
So I'm going to go ahead and type phunk results method.

106
00:07:32,790 --> 00:07:33,120
All right.

107
00:07:33,130 --> 00:07:33,350
Oops.

108
00:07:33,360 --> 00:07:37,160
And we're going to need to pass in a request of Vienne request.

109
00:07:37,170 --> 00:07:43,710
That's a vision request and we need to also give it the capability of using the errors that could come

110
00:07:43,710 --> 00:07:49,210
from our from our request so that's going to be of type error.

111
00:07:49,410 --> 00:07:49,770
OK.

112
00:07:49,830 --> 00:07:51,430
And there isn't always an error.

113
00:07:51,480 --> 00:07:53,330
That's why we're creating it as an optional.

114
00:07:53,610 --> 00:07:53,820
All right.

115
00:07:53,820 --> 00:07:58,220
So go ahead and give it some curly braces and we will come back to handle

116
00:08:00,490 --> 00:08:02,770
changing the label text.

117
00:08:02,830 --> 00:08:04,230
OK we'll come back to that in a moment.

118
00:08:04,240 --> 00:08:07,560
But right now we just need to be able to use result's method.

119
00:08:07,570 --> 00:08:08,130
OK.

120
00:08:08,470 --> 00:08:11,810
So our completion handler is going to be result's method.

121
00:08:12,190 --> 00:08:20,170
And what we're going to do is we're going to basically just call the name of our function here because

122
00:08:20,620 --> 00:08:26,250
when we create a request it automatically has a V.N. request and it automatically has an error.

123
00:08:26,440 --> 00:08:31,270
So that can just be passed in by default to this function so we don't actually need to put in any of

124
00:08:31,270 --> 00:08:31,990
the parameters.

125
00:08:31,990 --> 00:08:34,150
That's kind of the cool thing about using this.

126
00:08:34,230 --> 00:08:36,540
So we have a model that's our brain.

127
00:08:36,550 --> 00:08:40,320
We have a request that's kind of like the our brain is making a thought.

128
00:08:40,660 --> 00:08:45,310
And now the handler is going to basically take that thought and it's going to try to turn it into something

129
00:08:45,580 --> 00:08:46,700
that we can use.

130
00:08:46,720 --> 00:08:55,900
So let's go ahead and let's create a handler by typing let händler and that's going to be an image request

131
00:08:56,310 --> 00:08:57,320
handler.

132
00:08:57,340 --> 00:08:58,340
OK.

133
00:08:58,390 --> 00:09:00,270
Now of course there are lots of options here.

134
00:09:00,280 --> 00:09:08,140
As you can see CIA image CEG image C-v pixel buffer data and you are l what we're going to do is we're

135
00:09:08,140 --> 00:09:13,860
actually going to go ahead and just click on the one with data and options is necessary.

136
00:09:13,870 --> 00:09:15,300
We don't need to use the options.

137
00:09:15,340 --> 00:09:16,230
So we'll get rid of it.

138
00:09:16,450 --> 00:09:22,840
But we are going to pass in our data what data you ask our photo data OK that's the data we're going

139
00:09:22,840 --> 00:09:28,780
to give it so that it can analyze and determine what's in the image so pass in photo data and go ahead

140
00:09:28,780 --> 00:09:31,460
and unwrap it so that we can use it.

141
00:09:31,480 --> 00:09:37,300
Now what we need to do is we basically need to use our handler to perform our request our handler is

142
00:09:37,300 --> 00:09:40,540
kind of like a part of our brain that handles our ability to think.

143
00:09:40,540 --> 00:09:45,070
So our handlers are going to take our thought here and it's going to try to process it.

144
00:09:45,190 --> 00:09:45,670
OK.

145
00:09:45,940 --> 00:09:53,320
So let's go ahead and we're going to actually need to use try as well because the handler can also throw

146
00:09:53,320 --> 00:09:59,580
errors and so let's go ahead and type try handler perform and you'll see right here.

147
00:09:59,590 --> 00:10:02,550
It can take an array of V.N. requests.

148
00:10:02,830 --> 00:10:07,940
And so we're going to pass it an array with our request OK.

149
00:10:07,990 --> 00:10:12,130
So if we try to build and run here you'll notice it will work.

150
00:10:12,130 --> 00:10:14,670
But the issue is that we're not handling the errors.

151
00:10:14,680 --> 00:10:16,600
If there's a problem we should know.

152
00:10:16,810 --> 00:10:18,680
So to do that we're just going to use Debug.

153
00:10:18,690 --> 00:10:20,270
Print like we have been doing.

154
00:10:20,650 --> 00:10:22,950
And we're going to just call the error.

155
00:10:23,020 --> 00:10:23,940
There's an error.

156
00:10:24,020 --> 00:10:25,180
It will handle it here.

157
00:10:25,380 --> 00:10:25,730
OK.

158
00:10:25,750 --> 00:10:27,410
That's really easy.

159
00:10:27,410 --> 00:10:35,350
So now what we're doing is we're basically saying that we have a model k we are going this is like our

160
00:10:35,350 --> 00:10:37,600
brain can process the image.

161
00:10:37,600 --> 00:10:41,480
We have a request that is using our brain to make a thought.

162
00:10:41,620 --> 00:10:47,670
We have a handler that's going to basically take the data and compare it against our little thought.

163
00:10:47,740 --> 00:10:53,050
And then it's going to perform that request where it compares them and produces some data for us that

164
00:10:53,050 --> 00:10:56,940
is actually all we need to do to use machine learning.

165
00:10:56,950 --> 00:11:02,770
For now we're going to actually pull out the information from our request in this function result's

166
00:11:02,770 --> 00:11:03,410
method.

167
00:11:03,760 --> 00:11:08,200
And that's how we're going to actually display what our M-L model is thinking.

168
00:11:08,380 --> 00:11:15,340
So let's do that now go to results method and what we're going to do is we're going to create a constant

169
00:11:15,580 --> 00:11:18,010
to hold the results that come in from our request.

170
00:11:18,010 --> 00:11:21,730
Remember it just gets passed in straight here through our completion handler.

171
00:11:21,880 --> 00:11:28,930
So get rid of this commented out words it's not code and we're going to use guard Latt to create an

172
00:11:28,930 --> 00:11:32,470
instance of our results so go ahead and type guard.

173
00:11:32,470 --> 00:11:36,560
Let results and that is going to be equal to request.

174
00:11:36,580 --> 00:11:44,140
And if you type the period after that you can see that there is results inside of a request so very

175
00:11:44,140 --> 00:11:44,550
cool.

176
00:11:44,590 --> 00:11:50,710
We can get that but it needs to be we need to put it into an array because we're going to cycle through

177
00:11:50,710 --> 00:11:55,110
it and we're going to check to make sure that we get the most confident result.

178
00:11:55,110 --> 00:11:58,710
We don't want if it's like one tenth of a percent sure.

179
00:11:58,720 --> 00:12:02,110
We don't really care about that we want something that is almost positive.

180
00:12:02,110 --> 00:12:09,930
So go ahead and we're going to cast this as an array of V.N. classification observation.

181
00:12:10,570 --> 00:12:15,460
And you know what you guys can dive deeper into these descriptions for what these are but basically

182
00:12:15,460 --> 00:12:20,530
it is seen classification information produced by an image analysis request.

183
00:12:20,530 --> 00:12:21,570
All right.

184
00:12:21,580 --> 00:12:28,080
So it's basically using it to determine what is in the image that was sent in the request.

185
00:12:28,300 --> 00:12:32,140
So with a guard lead at the end we need to type else.

186
00:12:32,470 --> 00:12:33,940
And then inside of here it's pretty common.

187
00:12:33,940 --> 00:12:34,720
Just to return.

188
00:12:34,720 --> 00:12:39,850
So if it doesn't work if we if we don't get any results we're just going to return so that we don't

189
00:12:39,850 --> 00:12:46,210
have a crash if we do then we have a nice constant here called results that has our results.

190
00:12:46,270 --> 00:12:48,580
So that looks great.

191
00:12:48,580 --> 00:12:56,890
And beneath result's we're going to go ahead and type for classification in results.

192
00:12:56,890 --> 00:13:01,630
And the reason for that is because we are using V.N. classification observation and that's what we're

193
00:13:01,630 --> 00:13:07,990
doing is we're we're classifying objects in an image based on criteria that the male model understands.

194
00:13:07,990 --> 00:13:14,140
So for each classification let's think what we want to do here what we're going to do is basically we're

195
00:13:14,140 --> 00:13:21,580
going to set it up so that if it is more than 50 percent confident then it's going to say what it thinks

196
00:13:21,580 --> 00:13:22,150
it is.

197
00:13:22,180 --> 00:13:26,620
If it's less than 50 percent confident it's going to say I'm not really sure what this is.

198
00:13:26,620 --> 00:13:27,660
Please try again.

199
00:13:27,880 --> 00:13:28,970
OK simple as that.

200
00:13:29,230 --> 00:13:33,700
So to do that we're going to go ahead and type if classification.

201
00:13:33,880 --> 00:13:35,400
Confidence.

202
00:13:35,430 --> 00:13:37,070
Now you notice that.

203
00:13:37,150 --> 00:13:43,410
Well I might have to actually just a second if classification confidence is less than 0.5.

204
00:13:43,600 --> 00:13:44,810
50 percent.

205
00:13:44,950 --> 00:13:50,100
And if I select this you can see that V.N. confidence is of type float.

206
00:13:50,170 --> 00:13:50,630
OK.

207
00:13:50,650 --> 00:13:51,160
It's a float.

208
00:13:51,160 --> 00:13:52,240
It's a number that comes in.

209
00:13:52,240 --> 00:13:58,720
So we have 50 percent here 0.5 50 hundredths or five tenths.

210
00:13:58,720 --> 00:14:05,830
If it is less than 50 percent what we're going to do is we're going to set the text label here in our

211
00:14:06,640 --> 00:14:10,480
main upper bar we're going to set that to say I'm not sure what this is.

212
00:14:10,480 --> 00:14:11,660
Please try again.

213
00:14:11,950 --> 00:14:21,550
So go ahead and let's type self dot identification label text and that's going to be equal to.

214
00:14:21,730 --> 00:14:23,740
I'm not sure what this is.

215
00:14:23,740 --> 00:14:26,090
Please try again.

216
00:14:26,590 --> 00:14:26,920
All right.

217
00:14:26,920 --> 00:14:31,420
And you know what if we don't have if we're not really confident we shouldn't even show this confidence

218
00:14:31,420 --> 00:14:36,220
label so Gordon type self-confidence label that text and we're just going to say that to be an empty

219
00:14:36,220 --> 00:14:38,990
string because there's no need to show it.

220
00:14:39,010 --> 00:14:45,640
If there is not much confidence that it actually works OK and if that happens as well there's not really

221
00:14:45,700 --> 00:14:48,870
a need for it to continue so we're just going to call break.

222
00:14:48,880 --> 00:14:51,290
So that leaves the for loop.

223
00:14:51,400 --> 00:14:52,380
OK.

224
00:14:52,780 --> 00:14:58,170
What we're going to do next is what happens if we do get the proper results.

225
00:14:58,180 --> 00:15:02,790
Let's say that we get something it thinks it's 98 percent sure that it just saw an umbrella.

226
00:15:02,800 --> 00:15:04,350
OK so else.

227
00:15:04,570 --> 00:15:04,940
Right.

228
00:15:04,990 --> 00:15:10,000
That means it's greater than 50 percent if the confidence is more than 50 percent.

229
00:15:10,010 --> 00:15:17,030
Go ahead and type self identification label dot text and that's going to be equal to the classification

230
00:15:17,960 --> 00:15:21,500
identifier the identifier is what it thinks it saw.

231
00:15:21,500 --> 00:15:27,710
So in the example I showed you at the beginning of this course when you tap it takes a photo and it

232
00:15:27,710 --> 00:15:29,390
shows maybe umbrella.

233
00:15:29,780 --> 00:15:36,230
And we will program it later to speak out loud to say what it thinks it is but this identifier is a

234
00:15:36,230 --> 00:15:37,030
string.

235
00:15:37,080 --> 00:15:42,160
It returns a name of an object or an item and that's all we need to do next.

236
00:15:42,290 --> 00:15:47,360
We need to go ahead and set our confidence label to show how confident it thinks it is.

237
00:15:47,360 --> 00:15:54,440
So go ahead and type self confidence label that text and that's going to be equal to a string of course

238
00:15:54,440 --> 00:15:56,720
and we need to type confidence.

239
00:15:56,740 --> 00:15:57,280
OK.

240
00:15:57,290 --> 00:16:02,510
Just like we have here with the capital letters confidence and now we're going to use string interpolation

241
00:16:02,510 --> 00:16:07,590
to pass in a value that is not a string but we're going to cast it as a string so that it can be used.

242
00:16:07,790 --> 00:16:10,560
So we're going to use the classification.

243
00:16:10,730 --> 00:16:12,220
Confidence.

244
00:16:12,280 --> 00:16:12,560
OK.

245
00:16:12,560 --> 00:16:13,550
Pretty cool.

246
00:16:13,850 --> 00:16:20,210
And we're going to actually multiply that by 100 because right now if the value came in at 0.5 that

247
00:16:20,210 --> 00:16:22,170
might look like 0.5 percent.

248
00:16:22,190 --> 00:16:22,570
Sure.

249
00:16:22,580 --> 00:16:23,330
We don't want that.

250
00:16:23,330 --> 00:16:29,390
So if we were to multiply this by 100 it would move the decimal place over and it would say 50 percent.

251
00:16:29,390 --> 00:16:29,650
OK.

252
00:16:29,690 --> 00:16:33,630
So that's what we want because 0.5 is 50 percent.

253
00:16:33,770 --> 00:16:38,240
Now the issue is that it would be fifty point zero percent.

254
00:16:38,300 --> 00:16:42,970
And I don't want to have to deal with the additional numbers on the outside.

255
00:16:42,970 --> 00:16:48,470
So I'm actually going to cast this as an integer and then put another parentheses on the outside so

256
00:16:48,470 --> 00:16:50,410
that this number is a whole number.

257
00:16:50,540 --> 00:16:51,490
51 percent.

258
00:16:51,500 --> 00:16:53,160
37 percent.

259
00:16:53,240 --> 00:16:57,340
If you want you can leave it at thirty seven point nine eight seven six five percent sure.

260
00:16:57,350 --> 00:17:02,160
I just got kind of annoyed reading like eight numbers after the decimal place so I cast it as an ant.

261
00:17:02,180 --> 00:17:04,680
That's just my personal preference.

262
00:17:04,790 --> 00:17:05,450
And let's see.

263
00:17:05,450 --> 00:17:10,790
Confidence we have the classification and at the very end we need to add a percentage mark.

264
00:17:10,830 --> 00:17:12,080
All right.

265
00:17:12,230 --> 00:17:14,290
That looks pretty good.

266
00:17:15,020 --> 00:17:17,870
You know what do you guys want to go try it let's go see if it worked.

267
00:17:18,110 --> 00:17:23,180
OK we're going to go ahead and build and run it and it will show up here as soon as it builds and runs

268
00:17:23,180 --> 00:17:24,820
it will close.

269
00:17:25,160 --> 00:17:25,650
Maybe.

270
00:17:25,790 --> 00:17:26,900
Yeah there it is.

271
00:17:27,260 --> 00:17:27,920
All right.

272
00:17:28,100 --> 00:17:34,830
Building and installing to my phone it'll pop open.

273
00:17:34,870 --> 00:17:36,340
There it is.

274
00:17:36,340 --> 00:17:36,670
All right.

275
00:17:36,670 --> 00:17:38,680
Should we try it if it worked.

276
00:17:38,680 --> 00:17:40,110
We should tap the screen.

277
00:17:40,240 --> 00:17:45,670
It should analyze the photo and it should predict what it thinks it is and return a level of confidence.

278
00:17:45,670 --> 00:17:46,150
Let's try it.

279
00:17:46,150 --> 00:17:46,360
Ready.

280
00:17:46,360 --> 00:17:48,310
Three two one.

281
00:17:48,350 --> 00:17:51,710
Bing I'm not sure what this is.

282
00:17:51,710 --> 00:17:54,200
Please try again.

283
00:17:54,250 --> 00:17:55,390
I'm not sure what this is.

284
00:17:55,390 --> 00:17:58,900
Please try again.

285
00:17:59,160 --> 00:18:01,800
Interesting.

286
00:18:01,850 --> 00:18:03,970
So it does not appear to know what this is.

287
00:18:03,980 --> 00:18:11,430
Let's try some other other things maybe it might know what my wallet is my dustups wallet OK not sure

288
00:18:11,430 --> 00:18:12,590
what this is interesting.

289
00:18:12,600 --> 00:18:15,460
So what is the problem here.

290
00:18:16,770 --> 00:18:24,290
Let's see we're setting the label you know what let's go ahead let's actually print out the classification

291
00:18:24,290 --> 00:18:26,840
results.

292
00:18:29,000 --> 00:18:30,880
Let's print out the identifier.

293
00:18:30,900 --> 00:18:38,990
This way we can see everything that it's thinking through us that we know if it's.

294
00:18:39,060 --> 00:18:40,360
We can get an idea of what it's thinking.

295
00:18:40,400 --> 00:18:45,240
So when I tap the screen oh it says remote control and modem.

296
00:18:45,260 --> 00:18:50,270
I wonder why oh ok so I think I know what the problem is.

297
00:18:50,270 --> 00:18:52,640
So basically what we're doing is we're going through.

298
00:18:52,640 --> 00:18:57,950
If the confidence is less than 50 percent basically we go through we say I don't know what this is.

299
00:18:57,950 --> 00:19:00,580
And we break meaning we leave our for loop.

300
00:19:00,680 --> 00:19:06,830
But then if it is more than 50 percent confident it goes here and it identifies this but then it loops

301
00:19:06,830 --> 00:19:09,570
through again and it hits something that it's not confident on.

302
00:19:09,590 --> 00:19:14,690
And it shows I'm not sure what this is so when we hit something that it is confident on more than 50

303
00:19:14,690 --> 00:19:16,080
percent we should break.

304
00:19:16,370 --> 00:19:17,310
All right.

305
00:19:17,720 --> 00:19:20,310
OK so we should go ahead and do that.

306
00:19:20,690 --> 00:19:27,140
Let's break on both so that if it's not confident it breaks if it is not if it is totally confident

307
00:19:27,140 --> 00:19:30,320
on the first one it will just go right to here and that's fine.

308
00:19:30,320 --> 00:19:32,340
So let's let's build and run.

309
00:19:32,420 --> 00:19:37,130
Basically we were just cutting out our most confident result because we were going through some of the

310
00:19:37,160 --> 00:19:38,660
non-confidence ones first.

311
00:19:38,660 --> 00:19:41,730
So now that it's built let's take a look.

312
00:19:41,780 --> 00:19:48,500
When I tap on the screen to look at that remote control it's ninety nine percent confident and let's

313
00:19:48,500 --> 00:19:53,620
scan something that maybe it doesn't know maybe it doesn't know a Rubik's cube.

314
00:19:53,620 --> 00:19:54,330
Let's try it.

315
00:19:55,400 --> 00:19:55,710
OK.

316
00:19:55,740 --> 00:19:56,670
I'm not sure what this is.

317
00:19:56,670 --> 00:20:00,340
Please try again that's fine because I doubt it was trained to know what a Rubik's cube is.

318
00:20:00,570 --> 00:20:01,640
So that's good to know.

319
00:20:01,830 --> 00:20:06,270
When I scanned the remote again remote control 97 percent confident.

320
00:20:06,360 --> 00:20:07,090
Very cool.

321
00:20:07,140 --> 00:20:08,940
So it looks like it's working.

322
00:20:08,940 --> 00:20:10,190
This is awesome.

323
00:20:10,230 --> 00:20:13,080
So we have just successfully integrated machine learning.

324
00:20:13,080 --> 00:20:19,620
I kid you not it's that easy to pass in images make predictions based on a trained model we just gave

325
00:20:19,620 --> 00:20:24,540
our app the ability to think how incredible is that amazing work.

326
00:20:24,660 --> 00:20:31,440
In the next video we're actually going to set it up so that we can toggle the flash to turn on and off.

327
00:20:31,620 --> 00:20:36,810
And then we're going to actually at the very end we're going to set up a an avi speech synthesizer to

328
00:20:36,810 --> 00:20:42,690
speak the results to us thinking about maybe users who might be vision impaired who might not be able

329
00:20:42,690 --> 00:20:48,330
to see very well but want to classify objects they can hear what the app is seeing.

330
00:20:48,330 --> 00:20:49,290
Very very cool.

331
00:20:49,290 --> 00:20:52,040
So we're going to go ahead and move on to the next video.

332
00:20:52,050 --> 00:20:57,540
Amazing work with this one guys we are on our way to have a full fledged machine learning app that can

333
00:20:57,540 --> 00:21:00,170
analyze and identify items in photos.

334
00:21:00,180 --> 00:21:01,380
Very very cool.

335
00:21:01,410 --> 00:21:02,190
Awesome work guys.

336
00:21:02,190 --> 00:21:03,620
We'll see in the next video.
