﻿1
00:00:00,166 --> 00:00:03,333
All right, my friends, we're
almost at the end of this implementation.

2
00:00:03,333 --> 00:00:06,433
Congratulations again for implementing,
you know, part one.

3
00:00:06,433 --> 00:00:08,233
That was quite big technical.

4
00:00:08,233 --> 00:00:10,266
And then of course, part
two and part three to.

5
00:00:10,266 --> 00:00:12,333
Build and train our new.

6
00:00:12,333 --> 00:00:14,700
Artificial. Neural. Network, the CNN.

7
00:00:14,700 --> 00:00:17,333
And now we're going to tackle. Together
part four.

8
00:00:17,333 --> 00:00:19,333
To make a single prediction.

9
00:00:19,333 --> 00:00:21,833
Which. I remind will consist.

10
00:00:21,833 --> 00:00:23,100
Of. Predicting.

11
00:00:23,100 --> 00:00:24,566
What's. Inside.

12
00:00:24,566 --> 00:00:26,100
These two. Images.

13
00:00:26,100 --> 00:00:28,500
So this one and that one.

14
00:00:28,500 --> 00:00:30,200
So basically we will deploy our.

15
00:00:30,200 --> 00:00:33,200
CNN on each of. These. Single images.

16
00:00:33,366 --> 00:00:34,100
And we'll. Hope.

17
00:00:34,100 --> 00:00:36,366
That our CNN. Predicts a dog here.

18
00:00:36,366 --> 00:00:38,400
And of course. A cat here.

19
00:00:38,400 --> 00:00:39,166
All right.

20
00:00:39,166 --> 00:00:40,000
Let's do this.

21
00:00:40,000 --> 00:00:42,033
So you'll know how to basically deploy.

22
00:00:42,033 --> 00:00:44,200
CNN in production on a.

23
00:00:44,200 --> 00:00:46,166
Single observation.

24
00:00:46,166 --> 00:00:46,466
All right.

25
00:00:46,466 --> 00:00:48,200
So let's create a new code cell.

26
00:00:48,200 --> 00:00:48,966
And we're going to.

27
00:00:48,966 --> 00:00:49,766
Start by.

28
00:00:49,766 --> 00:00:52,733
Importing numpy.

29
00:00:52,733 --> 00:00:56,166
I should have actually left it
as our essential libraries.

30
00:00:56,166 --> 00:00:57,300
You know that's what I mean.

31
00:00:57,300 --> 00:01:00,000
We always need numpy
you know most of the time.

32
00:01:00,000 --> 00:01:00,633
So there we go.

33
00:01:00,633 --> 00:01:01,733
NumPy as NP.

34
00:01:01,733 --> 00:01:03,900
Yes please please at this shortcut.

35
00:01:03,900 --> 00:01:07,633
NP then we will import a new module.

36
00:01:07,633 --> 00:01:08,700
Which is actually.

37
00:01:08,700 --> 00:01:12,566
Something we almost import
before you know, at the beginning

38
00:01:12,566 --> 00:01:17,233
we imported the image data generator
from the image submodule.

39
00:01:17,233 --> 00:01:19,500
Of the preprocessing module
of the curious library.

40
00:01:19,500 --> 00:01:20,133
And in fact.

41
00:01:20,133 --> 00:01:20,566
What we would.

42
00:01:20,566 --> 00:01:23,133
Like to import now is that image module.

43
00:01:23,133 --> 00:01:24,633
But because we specifically.

44
00:01:24,633 --> 00:01:28,633
Imported something specific from that
module, well we need to import it again.

45
00:01:28,633 --> 00:01:30,633
So let's just do it quickly.

46
00:01:30,633 --> 00:01:33,633
So we're going to start from Keras.

47
00:01:34,300 --> 00:01:35,900
From which we're going to get.

48
00:01:35,900 --> 00:01:38,400
Access to the pre-processing module.

49
00:01:38,400 --> 00:01:39,300
Perfect.

50
00:01:39,300 --> 00:01:41,400
From which we're going to import.

51
00:01:41,400 --> 00:01:44,833
That. Image module. Great.

52
00:01:44,833 --> 00:01:45,133
All right.

53
00:01:45,133 --> 00:01:48,600
So now we have everything
we need to make that single prediction.

54
00:01:49,200 --> 00:01:49,900
And now the next.

55
00:01:49,900 --> 00:01:52,966
Step will be
of course to load that single.

56
00:01:52,966 --> 00:01:54,200
Image on which we want to.

57
00:01:54,200 --> 00:01:57,333
Deploy our model to predict
if there is a cat or dog.

58
00:01:57,333 --> 00:01:58,433
Inside.

59
00:01:58,433 --> 00:02:03,000
And therefore I'm going to create here
a new variable that will be exactly.

60
00:02:03,000 --> 00:02:06,700
That image and which will be actually
the input of the predict method.

61
00:02:07,200 --> 00:02:09,533
And we're going to. Call
that variable test.

62
00:02:09,533 --> 00:02:11,333
Underscore image.

63
00:02:11,333 --> 00:02:14,600
That's the image we want to test our model
on in production.

64
00:02:15,066 --> 00:02:17,266
And the first thing
we'll do with that. Variable. You know.

65
00:02:17,266 --> 00:02:17,700
The way.

66
00:02:17,700 --> 00:02:18,900
We're going to initialize.

67
00:02:18,900 --> 00:02:21,600
It is by. Simply loading it from.

68
00:02:21,600 --> 00:02:22,566
Our folder.

69
00:02:22,566 --> 00:02:26,333
Or same single prediction
folder that we have here.

70
00:02:26,800 --> 00:02:27,233
Okay.

71
00:02:27,233 --> 00:02:30,333
So the way we're going to do
this is with a.

72
00:02:30,333 --> 00:02:32,333
Specific function of the image.

73
00:02:32,333 --> 00:02:34,833
Submodule, which is the load.

74
00:02:34,833 --> 00:02:38,133
Img function
in which we can actually fine.

75
00:02:38,400 --> 00:02:42,266
Right here
by scrolling down a bit, you know.

76
00:02:42,300 --> 00:02:44,866
Or scrolling up actually.

77
00:02:44,866 --> 00:02:46,300
Where is it exactly.

78
00:02:46,300 --> 00:02:48,300
It is exactly.

79
00:02:48,300 --> 00:02:50,700
Here. Load image function.

80
00:02:50,700 --> 00:02:54,600
So we're going to use that function
to simply load an image into. The.

81
00:02:54,633 --> 00:02:55,800
Pil format.

82
00:02:55,800 --> 00:02:57,733
All right.
So that's the first. Format we'll. Get.

83
00:02:57,733 --> 00:03:00,433
But you're going to see that.
We will need. To adapt it.

84
00:03:00,433 --> 00:03:01,900
A bit more to make.

85
00:03:01,900 --> 00:03:04,900
It accepted by the predict. Method.

86
00:03:05,033 --> 00:03:05,466
Okay.

87
00:03:05,466 --> 00:03:07,700
So let's go back to our implementation.

88
00:03:07,700 --> 00:03:08,700
And there we. Go.

89
00:03:08,700 --> 00:03:10,600
Let's go first that.

90
00:03:10,600 --> 00:03:14,066
Image submodule from which we're going to.

91
00:03:14,066 --> 00:03:15,466
Call that load.

92
00:03:15,466 --> 00:03:18,466
Underscore img function.

93
00:03:18,833 --> 00:03:21,333
And inside this function will very simply
we have to enter.

94
00:03:21,333 --> 00:03:22,500
Two. Arguments.

95
00:03:22,500 --> 00:03:23,833
The first one is the.

96
00:03:23,833 --> 00:03:26,733
Path in quotes that starts. From the root.

97
00:03:26,733 --> 00:03:29,733
Which. Is, you know, our. Data set folder.

98
00:03:29,966 --> 00:03:35,400
And then going to that single prediction
folder and then specifying which image.

99
00:03:35,566 --> 00:03:38,333
We want to select.
So we'll start with this one.

100
00:03:38,333 --> 00:03:39,266
And therefore here we.

101
00:03:39,266 --> 00:03:42,733
Need to specify the path data
set slash single.

102
00:03:42,733 --> 00:03:46,100
Prediction. Slash character one.
All right.

103
00:03:46,100 --> 00:03:46,866
And that's exactly.

104
00:03:46,866 --> 00:03:50,333
What is expected
as the first argument of this load.

105
00:03:50,333 --> 00:03:52,566
Underscore img function.

106
00:03:52,566 --> 00:03:53,433
So let's do this.

107
00:03:53,433 --> 00:03:55,433
We have to enter it in quotes.

108
00:03:55,433 --> 00:03:57,733
So we start with the data set.

109
00:03:57,733 --> 00:03:59,333
Then slash it.

110
00:03:59,333 --> 00:04:01,566
Then we go. Into our single.

111
00:04:01,566 --> 00:04:02,400
Underscore.

112
00:04:02,400 --> 00:04:05,133
Prediction folder.

113
00:04:05,133 --> 00:04:06,666
And then. We specify.

114
00:04:06,666 --> 00:04:08,233
Which image we want to select.

115
00:04:08,233 --> 00:04:11,100
As this test. Image okay. And that's.

116
00:04:11,100 --> 00:04:12,700
Let's just do a copy. Paste.

117
00:04:12,700 --> 00:04:14,733
Make sure we don't make any mistake.

118
00:04:14,733 --> 00:04:15,966
So pressing enter.

119
00:04:15,966 --> 00:04:16,700
Copy that.

120
00:04:16,700 --> 00:04:17,900
And then.

121
00:04:17,900 --> 00:04:19,333
Let's paste that back.

122
00:04:19,333 --> 00:04:22,333
Inside our implementation. Right here.

123
00:04:22,333 --> 00:04:22,733
All right.

124
00:04:22,733 --> 00:04:23,200
And this.

125
00:04:23,200 --> 00:04:26,066
Will lead us to that image
which will be that.

126
00:04:26,066 --> 00:04:27,866
Test image. Variable.

127
00:04:27,866 --> 00:04:28,766
And then let's not forget.

128
00:04:28,766 --> 00:04:29,666
The extension.

129
00:04:29,666 --> 00:04:32,366
Dot jpg okay.

130
00:04:32,366 --> 00:04:34,500
So that will lead us to that image.

131
00:04:34,500 --> 00:04:37,833
So that this. Test image
will become exactly that image.

132
00:04:37,833 --> 00:04:40,800
Selected okay.
So that's for the first argument.

133
00:04:40,800 --> 00:04:41,766
And then.

134
00:04:41,766 --> 00:04:42,833
Let's add the second.

135
00:04:42,833 --> 00:04:45,266
Argument a very very important one.

136
00:04:45,266 --> 00:04:46,833
And actually. Compulsory.

137
00:04:46,833 --> 00:04:50,733
That's image which you know will become
the input of the predict method.

138
00:04:51,133 --> 00:04:53,800
Has to have the. Same. Size.

139
00:04:53,800 --> 00:04:55,433
As the one that. Was used.

140
00:04:55,433 --> 00:04:57,633
During the training. And remember.

141
00:04:57,633 --> 00:04:59,966
We actually resized our.

142
00:04:59,966 --> 00:05:02,266
Images into, you know.

143
00:05:02,266 --> 00:05:05,966
This size target size of 64 by 64.

144
00:05:05,966 --> 00:05:08,966
You know, whether it was
for the training set or the test set.

145
00:05:09,033 --> 00:05:10,200
And we specified this.

146
00:05:10,200 --> 00:05:11,933
Again when building the CNN.

147
00:05:11,933 --> 00:05:13,500
Right here with the input shape.

148
00:05:13,500 --> 00:05:14,400
So the size of.

149
00:05:14,400 --> 00:05:16,866
Any image we're going to work. With,
whether it is.

150
00:05:16,866 --> 00:05:19,266
To train our CNN or. To call the.

151
00:05:19,266 --> 00:05:20,400
Predict method.

152
00:05:20,400 --> 00:05:23,233
Has to be 64 by 64.

153
00:05:23,233 --> 00:05:23,966
Okay.

154
00:05:23,966 --> 00:05:26,700
And in order to. Specify this. Here,
we need to enter.

155
00:05:26,700 --> 00:05:29,700
As this. New argument the compulsory one.

156
00:05:29,833 --> 00:05:31,100
Target.

157
00:05:31,100 --> 00:05:33,933
Underscore. Size equal.

158
00:05:33,933 --> 00:05:35,400
And in some parenthesis.

159
00:05:35,400 --> 00:05:40,166
64 6464 by 64 okay.

160
00:05:40,366 --> 00:05:42,800
Perfect.
So now we have a first test image.

161
00:05:42,800 --> 00:05:44,233
But in order to be.

162
00:05:44,233 --> 00:05:47,366
Accepted by the predict method
which you know expects.

163
00:05:47,366 --> 00:05:48,666
A certain format.

164
00:05:48,666 --> 00:05:50,100
We have to do some extra work.

165
00:05:50,100 --> 00:05:52,166
Here on that test image.

166
00:05:52,166 --> 00:05:54,833
And that first. Extra work is. To convert.

167
00:05:54,833 --> 00:05:57,666
That. Pil. You know, Pil format.

168
00:05:57,666 --> 00:05:58,166
Which is a.

169
00:05:58,166 --> 00:06:01,366
Format of images into an array.

170
00:06:01,600 --> 00:06:06,666
Remember that the Predict method expects
as its input a 2D array.

171
00:06:06,666 --> 00:06:07,800
You know, you remember these.

172
00:06:07,800 --> 00:06:10,200
Double pair of square brackets,
which we used to.

173
00:06:10,200 --> 00:06:12,200
Input in the predict methods of.

174
00:06:12,200 --> 00:06:13,500
Our previous. Models.

175
00:06:13,500 --> 00:06:16,500
You know, when predicting the outcome
of a single observation.

176
00:06:16,733 --> 00:06:18,400
Well, here we're about to do exactly.

177
00:06:18,400 --> 00:06:20,333
The same by converting this.

178
00:06:20,333 --> 00:06:22,400
Test. Image into an array.

179
00:06:22,400 --> 00:06:25,133
And the. Way we're going to do
this is with.

180
00:06:25,133 --> 00:06:28,666
Another function of this image data
preprocessing module.

181
00:06:28,833 --> 00:06:30,633
Which is exactly.

182
00:06:30,633 --> 00:06:33,100
This one image two. Array, which.

183
00:06:33,100 --> 00:06:38,133
Converts indeed a image instance
into a numpy.

184
00:06:38,133 --> 00:06:40,166
Array, which is exactly the.

185
00:06:40,166 --> 00:06:40,966
Format of.

186
00:06:40,966 --> 00:06:43,966
Array expected by the predict. Method.

187
00:06:43,966 --> 00:06:46,700
So we're going to use that function
right away to convert.

188
00:06:46,700 --> 00:06:48,000
Our. Test image.

189
00:06:48,000 --> 00:06:51,100
Which so far has the Pil. Format into.

190
00:06:51,133 --> 00:06:53,500
This. Numpy array format.

191
00:06:53,500 --> 00:06:53,833
All right.

192
00:06:53,833 --> 00:06:55,033
So we're going to update.

193
00:06:55,033 --> 00:06:57,900
Our test image again.
So I'm calling it again.

194
00:06:57,900 --> 00:06:59,933
And then updating it by sending it.

195
00:06:59,933 --> 00:07:01,733
Equal to a new value.

196
00:07:01,733 --> 00:07:06,133
And well as you understood we're going to
use our image submodule again

197
00:07:06,133 --> 00:07:11,100
from which we're going to call this time
the I img underscore. Two.

198
00:07:11,133 --> 00:07:13,200
Underscore. Array.

199
00:07:13,200 --> 00:07:13,933
Function.

200
00:07:13,933 --> 00:07:14,966
And guess what?

201
00:07:14,966 --> 00:07:16,633
It has to take as input.

202
00:07:16,633 --> 00:07:19,166
Well very simply it just needs to take.

203
00:07:19,166 --> 00:07:24,600
That image in the format which we want
to convert into the numpy array format.

204
00:07:24,866 --> 00:07:26,100
And therefore well.

205
00:07:26,100 --> 00:07:26,800
The input will.

206
00:07:26,800 --> 00:07:29,733
Simply be that test. Image
and nothing else.

207
00:07:29,733 --> 00:07:31,100
You know, we only need.

208
00:07:31,100 --> 00:07:31,966
That.

209
00:07:31,966 --> 00:07:33,200
Image. Of which.

210
00:07:33,200 --> 00:07:35,033
We want to convert the format.

211
00:07:35,033 --> 00:07:36,600
Okay. So that the next step.

212
00:07:36,600 --> 00:07:38,000
But then we still have some.

213
00:07:38,000 --> 00:07:41,100
Extra work to do,
which is still related to the fact that.

214
00:07:41,100 --> 00:07:43,066
You know,
the predict method has to. Be called.

215
00:07:43,066 --> 00:07:44,200
On. The exact.

216
00:07:44,200 --> 00:07:46,100
Same format that. Was used.

217
00:07:46,100 --> 00:07:47,366
During the training.

218
00:07:47,366 --> 00:07:48,666
And well, remember

219
00:07:48,666 --> 00:07:52,533
that, you know, when preprocessing
our training set in our tests.

220
00:07:52,533 --> 00:07:54,500
It right here. In part one, data.

221
00:07:54,500 --> 00:07:58,133
Preprocessing
we actually created batches of.

222
00:07:58,133 --> 00:07:58,966
Images.

223
00:07:58,966 --> 00:08:03,200
Therefore, you know
our CNN was not trained on single images.

224
00:08:03,200 --> 00:08:04,966
You know, entering the network one.

225
00:08:04,966 --> 00:08:06,500
After the other, but it.

226
00:08:06,500 --> 00:08:09,066
Was trained with. Batches of. Images.

227
00:08:09,066 --> 00:08:09,700
And therefore we.

228
00:08:09,700 --> 00:08:12,066
Have this. Extra dimension corresponding.

229
00:08:12,066 --> 00:08:13,133
To the. Batch.

230
00:08:13,133 --> 00:08:16,966
You know, we have batch number one
containing 32 images, then batch

231
00:08:16,966 --> 00:08:21,133
number two containing other 32 images,
batch number three, etc..

232
00:08:21,400 --> 00:08:22,133
So we have this.

233
00:08:22,133 --> 00:08:25,300
Extra dimension of the batch
and even if now we're.

234
00:08:25,300 --> 00:08:25,966
About to.

235
00:08:25,966 --> 00:08:31,333
Deploy our model on a single image, well,
that single image still has to be into a.

236
00:08:31,333 --> 00:08:34,266
Batch. Even if we're going to have one
image in the batch.

237
00:08:34,266 --> 00:08:36,366
It needs to be into this batch
so that the.

238
00:08:36,366 --> 00:08:40,200
CNN model, and more specifically,
the predict method of the CNN model,

239
00:08:40,400 --> 00:08:41,433
can recognize.

240
00:08:41,433 --> 00:08:43,966
The batch as that. Extra dimension.

241
00:08:43,966 --> 00:08:46,333
And so, you guessed it, what we're about.

242
00:08:46,333 --> 00:08:48,266
To do now. Is just to add.

243
00:08:48,266 --> 00:08:49,233
An. Extra.

244
00:08:49,233 --> 00:08:52,066
Dimension
which will correspond to the batch

245
00:08:52,066 --> 00:08:55,333
and which will contain that image
into a batch.

246
00:08:55,633 --> 00:08:57,433
And the. Way to do this is.

247
00:08:57,433 --> 00:08:59,000
Once again by, you know, I.

248
00:08:59,000 --> 00:09:01,233
Just copied it before,
so I can just paste it.

249
00:09:01,233 --> 00:09:01,800
Once again.

250
00:09:01,800 --> 00:09:04,600
Update our test. Image by adding to.

251
00:09:04,600 --> 00:09:05,400
It this.

252
00:09:05,400 --> 00:09:08,400
Extra dimension
corresponding to the batch.

253
00:09:08,433 --> 00:09:09,000
And the way.

254
00:09:09,000 --> 00:09:11,166
To do this is. With numpy.

255
00:09:11,166 --> 00:09:11,500
You know.

256
00:09:11,500 --> 00:09:13,466
That's how we can always easily.

257
00:09:13,466 --> 00:09:15,266
Manipulate a numpy array.

258
00:09:15,266 --> 00:09:18,266
Now that you know, test
image is indeed a numpy array.

259
00:09:18,400 --> 00:09:21,366
And so I'm going to call numpy first,
which has a shortcut

260
00:09:21,366 --> 00:09:24,600
np from which I'm
going to call this function, which.

261
00:09:24,600 --> 00:09:26,700
Allows exactly you to add a fake.

262
00:09:26,700 --> 00:09:29,566
Dimension or you know, a dimension
corresponding. To the batch.

263
00:09:29,566 --> 00:09:30,666
And which is. Called the.

264
00:09:30,666 --> 00:09:34,500
Expand underscore dims function.

265
00:09:34,900 --> 00:09:36,000
And now. You guess.

266
00:09:36,000 --> 00:09:38,466
Once again, what do we have to input
inside this function.

267
00:09:38,466 --> 00:09:40,700
Well, we.
Have to input the image to which.

268
00:09:40,700 --> 00:09:42,333
We want to add this.

269
00:09:42,333 --> 00:09:44,500
Extra
dimension. Corresponding to the batch.

270
00:09:44,500 --> 00:09:46,500
So first I have to paste once.

271
00:09:46,500 --> 00:09:48,466
Again our test image.

272
00:09:48,466 --> 00:09:49,966
But we have to add.

273
00:09:49,966 --> 00:09:51,633
One extra argument here.

274
00:09:51,633 --> 00:09:54,500
Which is where we want to add that.

275
00:09:54,500 --> 00:09:55,800
Extra dimension.

276
00:09:55,800 --> 00:09:57,533
And that dimension of the batch.

277
00:09:57,533 --> 00:10:00,266
Is actually always the first. Dimension.

278
00:10:00,266 --> 00:10:02,933
You know, that makes sense.
You give first the.

279
00:10:02,933 --> 00:10:04,500
Batch of images and then inside.

280
00:10:04,500 --> 00:10:06,833
Each batch you get the. Different images.

281
00:10:06,833 --> 00:10:09,000
So it seems. Natural
to have the batch as the.

282
00:10:09,000 --> 00:10:09,866
First dimension.

283
00:10:09,866 --> 00:10:12,066
And to. Specify this, that's exactly what.

284
00:10:12,066 --> 00:10:15,000
We need to enter here.
As this extra. Argument.

285
00:10:15,000 --> 00:10:16,033
And that parameter to.

286
00:10:16,033 --> 00:10:21,366
Specify this is axis
which we have to set equal to zero okay.

287
00:10:21,366 --> 00:10:21,866
So that the.

288
00:10:21,866 --> 00:10:24,866
Dimension of the batch
which we're adding to our image.

289
00:10:24,966 --> 00:10:28,000
Will be the. First dimension. Okay.

290
00:10:28,200 --> 00:10:30,033
And now we're getting very close.

291
00:10:30,033 --> 00:10:32,166
To the final result because.

292
00:10:32,166 --> 00:10:34,000
Now is the time we can.

293
00:10:34,000 --> 00:10:35,766
Call the. Predict method.

294
00:10:35,766 --> 00:10:36,800
Because indeed.

295
00:10:36,800 --> 00:10:37,700
That test.

296
00:10:37,700 --> 00:10:40,800
Image,
which is not only in the right numpy.

297
00:10:40,800 --> 00:10:43,166
Array, but also which has that extra.

298
00:10:43,166 --> 00:10:44,433
Dimension corresponding to the.

299
00:10:44,433 --> 00:10:49,133
Batch, has exactly the right format
expected by.

300
00:10:49,133 --> 00:10:50,366
The predict method.

301
00:10:50,366 --> 00:10:53,366
And therefore here
we can create a new variable

302
00:10:53,400 --> 00:10:55,800
which we're going to call result.

303
00:10:55,800 --> 00:10:57,000
Because this will actually be the.

304
00:10:57,000 --> 00:10:58,333
Prediction. Of our.

305
00:10:58,333 --> 00:11:00,933
CNN called. With. Our test image.

306
00:11:00,933 --> 00:11:03,500
But I'm not calling it prediction. Yet
because it will.

307
00:11:03,500 --> 00:11:05,100
Only return 0 or 1.

308
00:11:05,100 --> 00:11:06,733
And then we'll have to do some encoding.

309
00:11:06,733 --> 00:11:09,566
Work to say what is zero.
And what is one. You know.

310
00:11:09,566 --> 00:11:12,333
Zero will actually be cat.
And one will. Actually be dog.

311
00:11:12,333 --> 00:11:15,000
I'll explain why later, but there we go.

312
00:11:15,000 --> 00:11:17,700
We're just going to call this
first result variable,

313
00:11:17,700 --> 00:11:20,500
which will be of course,
the output of the predict.

314
00:11:20,500 --> 00:11:22,300
Method call from our CNN.

315
00:11:22,300 --> 00:11:23,266
And so there we go. We need to.

316
00:11:23,266 --> 00:11:25,633
Take our. CNN. First.

317
00:11:25,633 --> 00:11:27,066
From which we're going to. Call.

318
00:11:27,066 --> 00:11:30,466
Of course
the predict method which will take.

319
00:11:30,466 --> 00:11:33,466
As input. Of course. Well our test.

320
00:11:33,500 --> 00:11:34,900
Image, which now.

321
00:11:34,900 --> 00:11:37,500
Has the right format expected by that.

322
00:11:37,500 --> 00:11:38,300
Predict method.

323
00:11:38,300 --> 00:11:39,366
So nothing else.

324
00:11:39,366 --> 00:11:42,366
We simply need to input this image here.

325
00:11:42,433 --> 00:11:44,566
And then now is the time to.

326
00:11:44,566 --> 00:11:46,466
Do that. Encoding work.

327
00:11:46,466 --> 00:11:49,166
So the way to figure out what is zero.

328
00:11:49,166 --> 00:11:50,100
And what is one. You know.

329
00:11:50,100 --> 00:11:53,100
If zero is cat or dog
and one is cat or dog,

330
00:11:53,100 --> 00:11:56,066
well, the trick is to call the class.

331
00:11:56,066 --> 00:11:57,600
Indices. Attribute.

332
00:11:57,600 --> 00:11:59,266
From our training set.

333
00:11:59,266 --> 00:12:00,300
Object.

334
00:12:00,300 --> 00:12:03,200
But since. Now we can't run this. Code.

335
00:12:03,200 --> 00:12:03,533
I'm just.

336
00:12:03,533 --> 00:12:05,033
Going to write the code that.

337
00:12:05,033 --> 00:12:07,000
Allows us to know which indices.

338
00:12:07,000 --> 00:12:08,400
Correspond to which classes.

339
00:12:08,400 --> 00:12:10,766
And then you can see that on Jupyter
Notebook.

340
00:12:10,766 --> 00:12:13,200
But I will just tell you that
by using this we.

341
00:12:13,200 --> 00:12:15,466
Actually know that one corresponds.

342
00:12:15,466 --> 00:12:16,600
To dog.

343
00:12:16,600 --> 00:12:19,300
And. Zero corresponds to cat.

344
00:12:19,300 --> 00:12:19,900
So to get.

345
00:12:19,900 --> 00:12:22,466
That information
we need to call our training set.

346
00:12:22,466 --> 00:12:24,566
Or actually the test set as. You want.

347
00:12:24,566 --> 00:12:25,900
And then from which we.

348
00:12:25,900 --> 00:12:28,733
Call this attribute called class.

349
00:12:28,733 --> 00:12:31,000
Underscore indices.

350
00:12:31,000 --> 00:12:32,333
Just like that.

351
00:12:32,333 --> 00:12:33,500
And by printing this.

352
00:12:33,500 --> 00:12:35,800
You will get the right class indices.

353
00:12:35,800 --> 00:12:36,833
And with this we.

354
00:12:36,833 --> 00:12:39,600
Get that dog corresponds. To one and cat.

355
00:12:39,600 --> 00:12:40,900
Corresponds to zero.

356
00:12:40,900 --> 00:12:42,033
And therefore our.

357
00:12:42,033 --> 00:12:43,800
Final step here, you know, to have a nice.

358
00:12:43,800 --> 00:12:45,633
Result displayed in the output.

359
00:12:45,633 --> 00:12:49,400
In the end, when we make that single
prediction on these two single images,

360
00:12:49,666 --> 00:12:53,333
well we're going to finish this with,
you know, an if condition.

361
00:12:53,633 --> 00:12:56,666
Where we're going to specify
that if the result.

362
00:12:57,000 --> 00:12:57,366
All right.

363
00:12:57,366 --> 00:12:59,700
Now remember that. Result. Contains.

364
00:12:59,700 --> 00:13:01,466
Also actually the result.

365
00:13:01,466 --> 00:13:04,200
Into a. Batch
because it was. Called on a test image.

366
00:13:04,200 --> 00:13:05,833
That was. Into a. Batch.

367
00:13:05,833 --> 00:13:08,866
So results also has this batch dimension.

368
00:13:09,200 --> 00:13:10,733
And therefore we're going to first.

369
00:13:10,733 --> 00:13:13,566
Get access to the batch.
And there are only one.

370
00:13:13,566 --> 00:13:16,166
And it has of course index zero because.

371
00:13:16,166 --> 00:13:18,200
Indexes in Python start. From zero.

372
00:13:18,200 --> 00:13:19,733
So here we get access to the batch.

373
00:13:19,733 --> 00:13:22,833
And then inside the batch
we're going to get access to.

374
00:13:22,933 --> 00:13:24,300
Well the first.

375
00:13:24,300 --> 00:13:26,133
And only element of the.

376
00:13:26,133 --> 00:13:28,000
Batch which corresponds to the.

377
00:13:28,000 --> 00:13:30,733
Prediction of that same. Cat or dog.

378
00:13:30,733 --> 00:13:31,966
One image.

379
00:13:31,966 --> 00:13:32,400
Right.

380
00:13:32,400 --> 00:13:33,400
We're dealing with a single.

381
00:13:33,400 --> 00:13:35,833
Image and therefore a single prediction.

382
00:13:35,833 --> 00:13:36,200
And to.

383
00:13:36,200 --> 00:13:37,066
Get that single.

384
00:13:37,066 --> 00:13:39,900
Prediction well we need to get inside this
batch of index.

385
00:13:39,900 --> 00:13:40,500
Zero.

386
00:13:40,500 --> 00:13:41,133
Well the.

387
00:13:41,133 --> 00:13:44,633
First and only element,
you know, the first and only prediction

388
00:13:44,866 --> 00:13:47,066
which has once again index. Zero.

389
00:13:47,066 --> 00:13:47,400
All right.

390
00:13:47,400 --> 00:13:49,533
So that's how we get exactly
the prediction.

391
00:13:49,533 --> 00:13:52,533
We want by first accessing the batch.

392
00:13:52,533 --> 00:13:55,533
And then accessing the single element
of the batch.

393
00:13:55,566 --> 00:13:56,000
And that's.

394
00:13:56,000 --> 00:13:57,433
Exactly our. Prediction.

395
00:13:57,433 --> 00:13:57,833
And so.

396
00:13:57,833 --> 00:13:59,333
If that prediction.

397
00:13:59,333 --> 00:14:02,900
Is. Equal notice
double equal here to. One.

398
00:14:03,200 --> 00:14:04,100
Then since we know.

399
00:14:04,100 --> 00:14:06,200
That one corresponds to duck.

400
00:14:06,200 --> 00:14:07,900
Then we'll create a new.

401
00:14:07,900 --> 00:14:10,366
Variable
which we're going to call prediction.

402
00:14:10,366 --> 00:14:14,733
And we'll set that prediction
variable equal to dog.

403
00:14:15,033 --> 00:14:17,300
And then I'm going to copy. This because.

404
00:14:17,300 --> 00:14:21,100
Then in an else condition
you know meaning if.

405
00:14:21,100 --> 00:14:22,400
The result.

406
00:14:22,400 --> 00:14:24,733
You know the prediction is equal. To zero.

407
00:14:24,733 --> 00:14:27,500
Then well prediction will.

408
00:14:27,500 --> 00:14:29,666
Be equal to cat.

409
00:14:29,666 --> 00:14:31,933
And then we simply finish this.

410
00:14:31,933 --> 00:14:33,933
With a less code cell.

411
00:14:33,933 --> 00:14:37,066
Containing a simple print of.

412
00:14:37,266 --> 00:14:39,700
The prediction. And that's it my friends.

413
00:14:39,700 --> 00:14:42,666
This is how you make a single prediction

414
00:14:42,666 --> 00:14:45,466
with a convolutional neural network.

415
00:14:45,466 --> 00:14:47,833
So now now it is to show time.

416
00:14:47,833 --> 00:14:49,700
It is time for. The exciting step.

417
00:14:49,700 --> 00:14:53,566
Because we're all going to sit comfortably
in our chair and we're going to shoot.

418
00:14:53,700 --> 00:14:55,500
This code. On Jupyter Notebook.
