Hello my friends,
and welcome to this very exciting new practical activity
on convolutional Neural networks.
If you're not too overwhelmed by the previous section, you know,
on artificial neural networks, well,
then you will smash with me this new section, because basically
a convolutional neural network, as you saw in the intuition lectures,
simply consists of adding an extra layer, which is the convolutional layer that,
as you understood, gives eyes to the eye, you know, to the deep learning model.
Because indeed, with a convolutional neural network,
we can now take an image or, you know, a 3D frame as an input,
as opposed to our previous artificial neural network,
which could only take an input vector containing some features as information.
Right. Remember the features of the customers in the bank.
But here we are going to add at the front a convolutional layer
which will be able to visualize or see images just like humans do.
So that's pretty exciting.
You know, we're making a step further towards human intelligence because,
you know, the fascination that scientists have about deep learning
is that, you know, it's the branch of machine learning that gets
artificial intelligence closer and closer to human intelligence.
And you will even see in some more advanced courses
on deep learning that not only we can add eyes to the AI,
but also some memory with the Lstm cells, but also some critic sense.
Well, there are a lot of innovations
in the deep learning science, which is absolutely fascinating.
But here we're going to focus on code.
And and so there you go my friends.
Let's start this new practical activity.
And as usual, before we go into this folder, let's make sure everyone here is
on this same page.
I give you the link to this folder right before this tutorial in the article.
And so now please follow me into parts eight Deep Learning,
where inside we're now going to go to
Convolutional Neural Networks.
All right.
So for this section exceptionally we only have an implementation in Python.
And that's for the simple reason that R is more useful for data mining
kind of machine learning or,
you know, advanced statistics, high dimensional statistics.
But I have not met any scientist in my life who does computer vision with R.
There are some libraries, like deep water, that can build a CNN
for computer vision, but really the best and most advanced
programing language for deep learning is definitely Python.
Thanks to the amazing libraries that have been developed by Google and Facebook.
You know, Google developed TensorFlow,
which is an amazing library for deep learning, and Facebook developed
PyTorch, which is another amazing deep learning library.
But these two TensorFlow and PyTorch are only used with Python.
And that's why, exceptionally for this section, there will not be an R
implementation of the CNN, right?
The A9 was fine
because we were still doing some advanced data mining with neural networks.
But for computer vision, really your best option is Python.
All right. So let's go into Python.
And now second different thing compared to before.
As you notice
you will only find the implementation here in this folder and not the data set.
That's for very good reason.
That's because the data set is actually super huge.
You know in terms of size it's a couple hundreds of megabytes
because the data set contains lots and lots of images of cats and dogs.
We're going to see them in a second.
But since it contains a lot of images, well, I did not include the data set here.
Otherwise.
You know, for those of you who want to download
the whole machine learning, it is it codes and data sets folder.
Well, it will take a lot more time if I include this data set here,
then if I left it separately, which is what I did, I left it separately
and I give it to you actually right before this tutorial in the same article.
So I hope you downloaded it, because right now we're going to have a look
right at the bottom of the article.
Right before this tutorial you had to download this exact folder.
Well, actually the zip folder, but I already unzipped it.
But you had to download this folder.
Section 40 Convolutional Neural Networks, which indeed contains
not only the codes in Ipynb format and py format, but mostly the data set.
The data set which contains three subfolders,
the first one containing all the images of cats and dogs.
But for the training set, which means that we're going to train our CNN model
on all these images of cats and dogs in the train set.
And then we have this other folder, which is the test set on which
we will actually evaluate our model with new images
of cats and dogs on which the model wasn't trained.
And finally, we have this little folder here which only contains two images.
And this will be just to test the model in production.
I know the single image.
So we will first take this image of this beautiful dog
to test that our CNN can detect.
The dog you know, can predict that indeed we have a dog in this image and we will
do the same with that image of a cat so that we can check that.
Indeed, our CNN predicts that there is a cat in this image.
So as you understood, I just explained the problem.
Actually, we're going to build and train a convolutional neural network
to recognize if there is a dog or a cat in an image.
Okay, so I hope you like the case study.
Of course,
this time it's not a business case study, but we're going to have a lot of fun
doing this.
And it's a great way to be introduced to convolutional neural networks.
And even if it's just an introduction, you will see that the CNN we're going to
build will be quite advanced and actually the implementation is quite advanced
with lots of technical tools, which will of course perfectly do the job at the end.
Okay, so that was the second specific thing.
The data set was given to you separately.
All right.
And just to show you quickly the training set and the test set.
So in the training set you have lots and lots of images of cats and dogs.
Actually you have 4000 images of cats
and 4000 images of dogs.
Right. I can take anyone. This is a dog,
another dog.
You know, many different breeds of dogs.
So if you love dogs, you're going to have a great time
looking at the images here, right.
And there we go.
So this is a very cute dog by the way.
Okay. And same for the cat.
You have many images of cats right.
Have different style different colors you know.
So whether you're a cat lover or dog lover
you will have great time looking at any of these images.
And same for the test set.
Well, you have 1000 images of cats here and same 1000 images of dogs.
So just to recap, in the training set you have until 8000 images
with 4000 images of cats and 4000 images of dogs.
And in the test set, you have in total 2000 images
with 1000 images of cats and 1000 images of dogs.
Right?
It's important to keep the numbers in mind because we're going to use them
in the implementation.
Okay, good.
So make sure to have this on your machine because of course we will use it
to run our code.
And now the third specific thing that I wanted to highlight in this
first introductory tutorial, it is the fact that
for the very first time, we won't be able to run our implementation,
which is this one convolutional neural network that ipynb.
We won't be able to run this implementation on Google Colab.
Why is that?
That's for the simple reason
that the data set is too big for a Google Colab notebook.
And therefore, for the very first time in this course,
I will show you how to run this implementation.
On July Notebook, because with Jupyter Notebook, we will be able to access
directly from your machine the data set, and we will run the code from our machine.
But within a Jupyter notebook.
Well notebook okay.
So what we'll do in fact in this new section is we will still,
you know, re-implement this whole code from scratch on Google Colab.
But at the end, once all this is implemented,
we will simply go to file here and then click here download dot Ipynb.
And this will download the Ipynb file which will be able to run on
Jupyter Notebook.
All right. So that's what will happen.
But we will stay on Google Colab to implement this together.
And speaking of which, well right now we have to save a copy in drive
because this is in read only mode and therefore we need to create a copy
to be able to modify and re-implement the whole code.
All right.
So let's do this as usual.
Let's delete all the code cells right.
Only the code cells.
Make sure to keep the text cells to keep that well highlighted structure.
Because indeed now we have a pretty long implementation.
So it's important to keep the structure so that we can,
you know, take a step back any time and know where we are going.
All right.
So let's remove only the code cells. And
now reaching part three, you know you're going
to recognize some of the same steps as before with the CNN.
Right. This is part four. And there we go.
All right.
So that's the whole structure. Let's have a look at it.
You know from here.
So at first we will import the libraries.
Then we have a structure in four parts.
Part one do reprocessing.
Part two building the CNN, part three training
the CNN and part four making a single prediction.
So it's exactly the same as before, you know, with the CNN,
only this time in part one, we will do a different work
because for the very first time, actually in the course, we won't be preprocess
a classic data set, but this time we will be pre-processing some images
and therefore the data preprocessing phase will be different.
It will consist of doing two steps.
First,
we will preprocess the training set and then we will preprocess the test set.
All right.
Then in part two we will build a CNN
know the whole architecture of the convolutional neural network.
We will initialize the CNN as a sequence of layers.
Then we will proceed to step one convolution to add
the convolutional layers.
Then we will proceed to step two pooling, more specifically max pooling.
Then we will add a second convolutional layer to make it, you know,
a deep neural network as opposed to a shallow neural network.
Then we will proceed to step three flattening to flatten the result
of all the convolutions and pooling into one dimensional vector,
which will become the input of a fully connected neural network.
And finally we will connect to all this, the final output layer.
Then in part three, when training the CNN will same as a.
And then we will first compile the CNN.
And then we will train the CNN on the training set while,
you know, evaluating it on the test set, we will clearly see that in the output.
And finally,
we will make a single prediction, you know, to test our model in prediction.
And so we will deploy our CNN on two different images,
one that will have a dog and the other that will have a cat.
And we will hope that our CNN can recognize
respectively, the dog and the cat.
All right. So that's our structure.
I hope you are ready for it.
And actually, I'm sure you are.
So if that's the case, well,
join me in the next tutorial to smash this implementation.
And until then, enjoy machine learning.