﻿1
00:00:00,133 --> 00:00:01,000
Hello my friends,

2
00:00:01,000 --> 00:00:05,600
and welcome to this very exciting
new practical activity

3
00:00:05,733 --> 00:00:08,633
on convolutional Neural networks.

4
00:00:08,633 --> 00:00:11,400
If you're not too overwhelmed
by the previous section, you know,

5
00:00:11,400 --> 00:00:13,300
on artificial neural networks, well,

6
00:00:13,300 --> 00:00:17,333
then you will smash with me
this new section, because basically

7
00:00:17,333 --> 00:00:20,866
a convolutional neural network,
as you saw in the intuition lectures,

8
00:00:21,100 --> 00:00:26,500
simply consists of adding an extra layer,
which is the convolutional layer that,

9
00:00:26,500 --> 00:00:31,133
as you understood, gives eyes to the eye,
you know, to the deep learning model.

10
00:00:31,166 --> 00:00:33,966
Because indeed,
with a convolutional neural network,

11
00:00:33,966 --> 00:00:38,700
we can now take an image or,
you know, a 3D frame as an input,

12
00:00:38,933 --> 00:00:42,100
as opposed to our previous
artificial neural network,

13
00:00:42,100 --> 00:00:47,266
which could only take an input vector
containing some features as information.

14
00:00:47,266 --> 00:00:49,966
Right. Remember the features
of the customers in the bank.

15
00:00:49,966 --> 00:00:54,100
But here we are going to add at the front
a convolutional layer

16
00:00:54,100 --> 00:00:59,400
which will be able to visualize
or see images just like humans do.

17
00:00:59,566 --> 00:01:00,733
So that's pretty exciting.

18
00:01:00,733 --> 00:01:04,833
You know, we're making a step further
towards human intelligence because,

19
00:01:04,833 --> 00:01:08,733
you know, the fascination
that scientists have about deep learning

20
00:01:08,966 --> 00:01:11,766
is that, you know, it's
the branch of machine learning that gets

21
00:01:11,766 --> 00:01:15,600
artificial intelligence
closer and closer to human intelligence.

22
00:01:15,800 --> 00:01:18,833
And you will even see
in some more advanced courses

23
00:01:18,866 --> 00:01:21,866
on deep learning that
not only we can add eyes to the AI,

24
00:01:21,866 --> 00:01:26,900
but also some memory with the Lstm cells,
but also some critic sense.

25
00:01:27,066 --> 00:01:29,100
Well, there are a lot of innovations

26
00:01:29,100 --> 00:01:32,133
in the deep learning science,
which is absolutely fascinating.

27
00:01:32,133 --> 00:01:34,533
But here we're going to focus on code.

28
00:01:34,533 --> 00:01:36,400
And and so there you go my friends.

29
00:01:36,400 --> 00:01:39,400
Let's start this new practical activity.

30
00:01:39,600 --> 00:01:43,100
And as usual, before we go into this
folder, let's make sure everyone here is

31
00:01:43,100 --> 00:01:44,566
on this same page.

32
00:01:44,566 --> 00:01:48,333
I give you the link to this folder
right before this tutorial in the article.

33
00:01:48,333 --> 00:01:52,333
And so now please follow me into parts
eight Deep Learning,

34
00:01:52,800 --> 00:01:55,800
where inside we're now going to go to

35
00:01:55,800 --> 00:01:58,700
Convolutional Neural Networks.

36
00:01:58,700 --> 00:01:59,000
All right.

37
00:01:59,000 --> 00:02:04,233
So for this section exceptionally
we only have an implementation in Python.

38
00:02:04,233 --> 00:02:09,333
And that's for the simple reason
that R is more useful for data mining

39
00:02:09,333 --> 00:02:10,533
kind of machine learning or,

40
00:02:10,533 --> 00:02:13,533
you know, advanced statistics,
high dimensional statistics.

41
00:02:13,633 --> 00:02:19,000
But I have not met any scientist in
my life who does computer vision with R.

42
00:02:19,000 --> 00:02:23,533
There are some libraries, like deep water,
that can build a CNN

43
00:02:23,533 --> 00:02:27,766
for computer vision,
but really the best and most advanced

44
00:02:27,766 --> 00:02:31,600
programing language
for deep learning is definitely Python.

45
00:02:31,600 --> 00:02:36,100
Thanks to the amazing libraries that have
been developed by Google and Facebook.

46
00:02:36,100 --> 00:02:38,266
You know, Google developed TensorFlow,

47
00:02:38,266 --> 00:02:41,966
which is an amazing library
for deep learning, and Facebook developed

48
00:02:42,000 --> 00:02:45,400
PyTorch, which is another amazing
deep learning library.

49
00:02:45,400 --> 00:02:49,200
But these two TensorFlow and PyTorch
are only used with Python.

50
00:02:49,200 --> 00:02:53,166
And that's why, exceptionally
for this section, there will not be an R

51
00:02:53,200 --> 00:02:55,133
implementation of the CNN, right?

52
00:02:55,133 --> 00:02:56,200
The A9 was fine

53
00:02:56,200 --> 00:03:00,133
because we were still doing some advanced
data mining with neural networks.

54
00:03:00,300 --> 00:03:04,566
But for computer vision, really
your best option is Python.

55
00:03:05,066 --> 00:03:07,433
All right. So let's go into Python.

56
00:03:07,433 --> 00:03:10,733
And now second different thing
compared to before.

57
00:03:10,900 --> 00:03:11,600
As you notice

58
00:03:11,600 --> 00:03:16,266
you will only find the implementation
here in this folder and not the data set.

59
00:03:16,700 --> 00:03:18,533
That's for very good reason.

60
00:03:18,533 --> 00:03:21,433
That's because the data set
is actually super huge.

61
00:03:21,433 --> 00:03:24,400
You know in terms of size
it's a couple hundreds of megabytes

62
00:03:24,400 --> 00:03:29,666
because the data set contains
lots and lots of images of cats and dogs.

63
00:03:29,666 --> 00:03:31,266
We're going to see them in a second.

64
00:03:31,266 --> 00:03:36,600
But since it contains a lot of images,
well, I did not include the data set here.

65
00:03:36,766 --> 00:03:37,366
Otherwise.

66
00:03:37,366 --> 00:03:39,700
You know, for those of you
who want to download

67
00:03:39,700 --> 00:03:42,733
the whole machine learning, it is
it codes and data sets folder.

68
00:03:42,900 --> 00:03:46,500
Well, it will take a lot more time
if I include this data set here,

69
00:03:46,733 --> 00:03:50,366
then if I left it separately,
which is what I did, I left it separately

70
00:03:50,366 --> 00:03:54,200
and I give it to you actually right
before this tutorial in the same article.

71
00:03:54,300 --> 00:03:57,833
So I hope you downloaded it, because
right now we're going to have a look

72
00:03:58,066 --> 00:04:00,000
right at the bottom of the article.

73
00:04:00,000 --> 00:04:04,633
Right before this tutorial
you had to download this exact folder.

74
00:04:04,633 --> 00:04:07,633
Well, actually the zip folder,
but I already unzipped it.

75
00:04:07,800 --> 00:04:09,600
But you had to download this folder.

76
00:04:09,600 --> 00:04:13,766
Section 40 Convolutional Neural Networks,
which indeed contains

77
00:04:13,766 --> 00:04:19,900
not only the codes in Ipynb format
and py format, but mostly the data set.

78
00:04:20,166 --> 00:04:24,000
The data set
which contains three subfolders,

79
00:04:24,200 --> 00:04:28,700
the first one containing
all the images of cats and dogs.

80
00:04:28,700 --> 00:04:33,300
But for the training set, which means that
we're going to train our CNN model

81
00:04:33,300 --> 00:04:36,766
on all these images of cats
and dogs in the train set.

82
00:04:37,200 --> 00:04:40,700
And then we have this other folder,
which is the test set on which

83
00:04:40,700 --> 00:04:44,566
we will actually evaluate our model
with new images

84
00:04:44,566 --> 00:04:47,600
of cats and dogs
on which the model wasn't trained.

85
00:04:48,033 --> 00:04:52,533
And finally, we have this little folder
here which only contains two images.

86
00:04:52,833 --> 00:04:55,833
And this will be just to test
the model in production.

87
00:04:56,033 --> 00:04:57,533
I know the single image.

88
00:04:57,533 --> 00:05:01,133
So we will first take this image
of this beautiful dog

89
00:05:01,366 --> 00:05:04,600
to test that our CNN can detect.

90
00:05:04,666 --> 00:05:08,833
The dog you know, can predict that indeed
we have a dog in this image and we will

91
00:05:08,833 --> 00:05:13,233
do the same with that image of a cat
so that we can check that.

92
00:05:13,233 --> 00:05:17,066
Indeed, our CNN predicts
that there is a cat in this image.

93
00:05:17,366 --> 00:05:19,800
So as you understood,
I just explained the problem.

94
00:05:19,800 --> 00:05:24,266
Actually, we're going to build and train
a convolutional neural network

95
00:05:24,466 --> 00:05:29,066
to recognize
if there is a dog or a cat in an image.

96
00:05:29,300 --> 00:05:31,433
Okay, so I hope you like the case study.

97
00:05:31,433 --> 00:05:31,833
Of course,

98
00:05:31,833 --> 00:05:35,300
this time it's not a business case study,
but we're going to have a lot of fun

99
00:05:35,300 --> 00:05:35,833
doing this.

100
00:05:35,833 --> 00:05:39,533
And it's a great way to be introduced
to convolutional neural networks.

101
00:05:39,700 --> 00:05:43,366
And even if it's just an introduction,
you will see that the CNN we're going to

102
00:05:43,366 --> 00:05:47,400
build will be quite advanced and actually
the implementation is quite advanced

103
00:05:47,400 --> 00:05:52,133
with lots of technical tools, which will
of course perfectly do the job at the end.

104
00:05:52,800 --> 00:05:55,333
Okay,
so that was the second specific thing.

105
00:05:55,333 --> 00:05:58,200
The data set was given to you separately.

106
00:05:58,200 --> 00:05:58,600
All right.

107
00:05:58,600 --> 00:06:01,666
And just to show you quickly
the training set and the test set.

108
00:06:01,666 --> 00:06:05,866
So in the training set you have lots
and lots of images of cats and dogs.

109
00:06:05,866 --> 00:06:09,200
Actually you have 4000 images of cats

110
00:06:09,200 --> 00:06:12,300
and 4000 images of dogs.

111
00:06:12,600 --> 00:06:15,533
Right. I can take anyone. This is a dog,

112
00:06:16,933 --> 00:06:17,966
another dog.

113
00:06:17,966 --> 00:06:20,600
You know, many different breeds of dogs.

114
00:06:20,600 --> 00:06:23,833
So if you love dogs,
you're going to have a great time

115
00:06:23,833 --> 00:06:26,833
looking at the images here, right.

116
00:06:27,466 --> 00:06:28,200
And there we go.

117
00:06:28,200 --> 00:06:30,500
So this is a very cute dog by the way.

118
00:06:30,500 --> 00:06:31,833
Okay. And same for the cat.

119
00:06:31,833 --> 00:06:34,833
You have many images of cats right.

120
00:06:35,000 --> 00:06:37,700
Have different style different colors
you know.

121
00:06:37,700 --> 00:06:39,733
So whether you're a cat lover or dog lover

122
00:06:39,733 --> 00:06:43,400
you will have great time
looking at any of these images.

123
00:06:43,800 --> 00:06:45,166
And same for the test set.

124
00:06:45,166 --> 00:06:51,000
Well, you have 1000 images of cats here
and same 1000 images of dogs.

125
00:06:51,266 --> 00:06:55,466
So just to recap, in the training set
you have until 8000 images

126
00:06:55,466 --> 00:06:59,066
with 4000 images of cats
and 4000 images of dogs.

127
00:06:59,366 --> 00:07:02,400
And in the test set,
you have in total 2000 images

128
00:07:02,400 --> 00:07:06,300
with 1000 images of cats
and 1000 images of dogs.

129
00:07:06,366 --> 00:07:06,766
Right?

130
00:07:06,766 --> 00:07:09,766
It's important to keep the numbers in mind
because we're going to use them

131
00:07:10,000 --> 00:07:11,900
in the implementation.

132
00:07:11,900 --> 00:07:12,600
Okay, good.

133
00:07:12,600 --> 00:07:16,466
So make sure to have this on your machine
because of course we will use it

134
00:07:16,633 --> 00:07:18,566
to run our code.

135
00:07:18,566 --> 00:07:23,100
And now the third specific thing
that I wanted to highlight in this

136
00:07:23,100 --> 00:07:26,933
first introductory tutorial,
it is the fact that

137
00:07:27,033 --> 00:07:32,200
for the very first time, we won't be able
to run our implementation,

138
00:07:32,200 --> 00:07:35,800
which is this one
convolutional neural network that ipynb.

139
00:07:36,166 --> 00:07:40,200
We won't be able to run this
implementation on Google Colab.

140
00:07:40,533 --> 00:07:41,633
Why is that?

141
00:07:41,633 --> 00:07:42,800
That's for the simple reason

142
00:07:42,800 --> 00:07:46,733
that the data set
is too big for a Google Colab notebook.

143
00:07:47,133 --> 00:07:50,133
And therefore,
for the very first time in this course,

144
00:07:50,366 --> 00:07:53,666
I will show you
how to run this implementation.

145
00:07:53,866 --> 00:07:58,700
On July Notebook, because with Jupyter
Notebook, we will be able to access

146
00:07:58,700 --> 00:08:03,533
directly from your machine the data set,
and we will run the code from our machine.

147
00:08:03,533 --> 00:08:05,500
But within a Jupyter notebook.

148
00:08:05,500 --> 00:08:07,166
Well notebook okay.

149
00:08:07,166 --> 00:08:11,300
So what we'll do in fact in
this new section is we will still,

150
00:08:11,300 --> 00:08:16,000
you know, re-implement this whole code
from scratch on Google Colab.

151
00:08:16,000 --> 00:08:19,000
But at the end, once
all this is implemented,

152
00:08:19,166 --> 00:08:25,000
we will simply go to file here
and then click here download dot Ipynb.

153
00:08:25,000 --> 00:08:29,966
And this will download the Ipynb file
which will be able to run on

154
00:08:29,966 --> 00:08:31,400
Jupyter Notebook.

155
00:08:31,400 --> 00:08:32,900
All right. So that's what will happen.

156
00:08:32,900 --> 00:08:35,800
But we will stay on Google Colab
to implement this together.

157
00:08:35,800 --> 00:08:40,333
And speaking of which, well right now
we have to save a copy in drive

158
00:08:40,333 --> 00:08:44,800
because this is in read only mode
and therefore we need to create a copy

159
00:08:45,033 --> 00:08:48,533
to be able to modify and re-implement
the whole code.

160
00:08:49,066 --> 00:08:49,366
All right.

161
00:08:49,366 --> 00:08:50,800
So let's do this as usual.

162
00:08:50,800 --> 00:08:53,433
Let's delete all the code cells right.

163
00:08:53,433 --> 00:08:54,466
Only the code cells.

164
00:08:54,466 --> 00:08:58,866
Make sure to keep the text cells
to keep that well highlighted structure.

165
00:08:58,866 --> 00:09:02,200
Because indeed
now we have a pretty long implementation.

166
00:09:02,200 --> 00:09:05,233
So it's important to keep the structure
so that we can,

167
00:09:05,233 --> 00:09:08,800
you know, take a step back
any time and know where we are going.

168
00:09:09,100 --> 00:09:09,700
All right.

169
00:09:09,700 --> 00:09:14,400
So let's remove only the code cells. And

170
00:09:15,366 --> 00:09:18,066
now reaching
part three, you know you're going

171
00:09:18,066 --> 00:09:21,633
to recognize some of the same steps
as before with the CNN.

172
00:09:22,066 --> 00:09:24,933
Right. This is part four. And there we go.

173
00:09:24,933 --> 00:09:25,200
All right.

174
00:09:25,200 --> 00:09:27,500
So that's the whole structure.
Let's have a look at it.

175
00:09:27,500 --> 00:09:28,633
You know from here.

176
00:09:28,633 --> 00:09:31,133
So at first we will import the libraries.

177
00:09:31,133 --> 00:09:33,066
Then we have a structure in four parts.

178
00:09:33,066 --> 00:09:34,933
Part one do reprocessing.

179
00:09:34,933 --> 00:09:38,266
Part two building the CNN, part
three training

180
00:09:38,266 --> 00:09:41,700
the CNN and part
four making a single prediction.

181
00:09:41,966 --> 00:09:44,966
So it's exactly the same as before,
you know, with the CNN,

182
00:09:45,000 --> 00:09:48,200
only this time in part one,
we will do a different work

183
00:09:48,200 --> 00:09:52,766
because for the very first time, actually
in the course, we won't be preprocess

184
00:09:53,200 --> 00:09:57,700
a classic data set, but this time
we will be pre-processing some images

185
00:09:57,966 --> 00:10:00,933
and therefore the data
preprocessing phase will be different.

186
00:10:00,933 --> 00:10:02,866
It will consist of doing two steps.

187
00:10:02,866 --> 00:10:03,433
First,

188
00:10:03,433 --> 00:10:07,700
we will preprocess the training set
and then we will preprocess the test set.

189
00:10:08,200 --> 00:10:08,700
All right.

190
00:10:08,700 --> 00:10:10,833
Then in part two we will build a CNN

191
00:10:10,833 --> 00:10:13,833
know the whole architecture
of the convolutional neural network.

192
00:10:14,000 --> 00:10:17,000
We will initialize the CNN
as a sequence of layers.

193
00:10:17,033 --> 00:10:20,133
Then we will proceed
to step one convolution to add

194
00:10:20,133 --> 00:10:21,733
the convolutional layers.

195
00:10:21,733 --> 00:10:25,633
Then we will proceed to step two pooling,
more specifically max pooling.

196
00:10:25,900 --> 00:10:29,366
Then we will add a second
convolutional layer to make it, you know,

197
00:10:29,366 --> 00:10:33,000
a deep neural network
as opposed to a shallow neural network.

198
00:10:33,266 --> 00:10:37,400
Then we will proceed to step three
flattening to flatten the result

199
00:10:37,400 --> 00:10:41,233
of all the convolutions
and pooling into one dimensional vector,

200
00:10:41,400 --> 00:10:45,333
which will become the input
of a fully connected neural network.

201
00:10:45,500 --> 00:10:49,200
And finally we will connect to all this,
the final output layer.

202
00:10:49,633 --> 00:10:53,066
Then in part three,
when training the CNN will same as a.

203
00:10:53,066 --> 00:10:55,266
And then we will first compile the CNN.

204
00:10:55,266 --> 00:10:58,500
And then we will train the CNN
on the training set while,

205
00:10:58,733 --> 00:11:03,066
you know, evaluating it on the test set,
we will clearly see that in the output.

206
00:11:03,400 --> 00:11:04,233
And finally,

207
00:11:04,233 --> 00:11:08,400
we will make a single prediction,
you know, to test our model in prediction.

208
00:11:08,633 --> 00:11:12,366
And so we will deploy our CNN
on two different images,

209
00:11:12,600 --> 00:11:15,733
one that will have a dog
and the other that will have a cat.

210
00:11:15,733 --> 00:11:18,733
And we will hope that our CNN
can recognize

211
00:11:18,766 --> 00:11:21,766
respectively, the dog and the cat.

212
00:11:21,766 --> 00:11:24,300
All right. So that's our structure.

213
00:11:24,300 --> 00:11:25,633
I hope you are ready for it.

214
00:11:25,633 --> 00:11:27,466
And actually, I'm sure you are.

215
00:11:27,466 --> 00:11:28,866
So if that's the case, well,

216
00:11:28,866 --> 00:11:32,700
join me in the next tutorial
to smash this implementation.

217
00:11:32,700 --> 00:11:34,733
And until then, enjoy machine learning.
