Now, let's move on to building of a model in Paris.
So if you recall from those slides in our previous pay to watch lesson, this is a CNN model that we're
about to build.
We take the input image.
We have tree by tree filters.
We get it to the twenty to twenty two feature map set of 26 by 26.
Then we have another conflict.
So we actually use a tree battery filter there.
And then we get these feature map sort of it.
We use 64 filters in that case.
So now we get 64 feature maps.
We apply réélu activation layers to these.
Then we have a max pool.
We also play re-look to this as well.
We have 12 by 12 because it's half that size.
We have 64.
Because the 64 filters flatten it for the connected layer.
All of these nodes are connected and upwards to the soft max, which is the output, and we get the
probabilities out of it.
So in Keros, it's actually quite easy to construct complicated CNN's.
So these are just some details of what we're doing here, what I just went over.
Now let's take a look at the code where we actually build our CNN.
So it's quite a lot of text to have.
There's a lot of comments that explain what we do.
So it would be helpful if you paused sometimes or just take a look at your own notebook and go through
this on your own.
So these are the inputs here.
So in Keros, when TensorFlow, we have to import all of the objects.
These are the building blocks of the layers that we would be using and see it in the CNN.
So we have the sequential sequential basically says that we're building a sequential model, which means
that it's each layer is connected to the next.
Then these are two of the model is building as well.
From the layers library.
We have then struck out flatten builds have convex pool.
This can all be in one layer, but is just on two lines.
So to make it shorter, Keros we import the back end is key because we occasionally need to access that.
And then we have this stochastic gradient descent from the as part of the library.
So we have all of the building blocks we need if we imported them and look how easy this is in the US
to construct a model with this new model dot ad after we create the model up here.
We added a clumsily are here.
We specify how many filters we specify the kernel size here, tree by tree specify the activation we
want to use redo and input shape, which is input shape we took from up here or there.
Was it?
Yeah, up here 28 by 28 comma one, which is the depth of the image.
And that's it.
So we just cleared of this conflict.
Let's make our second conflict now.
So now we can.
We want to make a 64 filter tree by tree kernel size.
We don't actually have to write content, says Eq..
You can.
The function knows that a second parameter is going to be kernel size, and then we specify the activation
activation layer again using real.
Now you may have wondered why we didn't.
We didn't need to set padding or straight.
If we can, we can actually add in a padding or straight parameter, like putting padding equal to one
or two.
However, we using a default values and default values, we didn't use any padding and we used stride
of one for both conflicts.
Next, we use a max boot again.
And similarly, with Max boot, we can specify inside here we could put Stride Eq. four or whatever
we wanted to use.
However, we're not going to just yet because we're going to use default one.
So we add the Max Boulia here and then we add the flattened layer here.
We just basically flattened latex the previous input and flattened it.
I notice we don't have to link like have X equal to this and have an input, but would carry us when
we do model it.
Add it adds sequentially each layer.
So we know each layer feeds into the other layer.
And when we do flatten here, it just flattens the output of the Max Boulia right here.
That gives us nine thousand two hundred sixteen by one dimension of that.
Come and take in this.
Think of this next.
We have this dense layer, which is once in twenty eight layers using an activation of rlU again.
So we just take that and feed it into there, take that output and then fit it into the soft max layer
here now in the loss of max layer.
We need to specify the input size and the input size as a number of classes, which is 10, which is
what we set that variable up here.
10.
Consider printed it out just to make sure.
So that's what we need for the soft max layer right now.
And then all we have to do after that is just to model that compile.
This creates an object that stores a model that we just created that's not above the code right there.
So what we do here in the model to compile, we can specify, just like in Potawatomi, specified all
across an arbitrary and.
Entropy, lost function and optimizer, we specify those things here in carrots, we have to attitude
metric here, metric being accuracy, which is what we want to monitor during the training process.
It's quite simple and you can put because it's a list, you can put multiple things here, like if you
wanted to do loss as well, you could have done it like that.
So let's take it out for now.
And then at the end, this is a very good practice that I tend to do a lot.
Print the model of summary and it gives you a breakdown of the little the output shape number of parameters
in it.
And if you remember from all the slides, these were the parameters we got got when we created this
neural net to CNN.
And it gives you the total trainable parameters, total parameters, non-tradable parameters which are
zero in this case.
So it's pretty cool.
So we'll stop there in the next section, though we'll start training on model.
But this here just wanted to show you this is the same could above here without all the comments, and
you can see how short and easy it is to construct that fairly.
I mean, it's not a complicated CNN, it's a basic CNN, but you can see how easy it was to construct
at CNN using cameras right now and defined a loss and optimizer.
So it's quite good, quite nice, and hope you took a lot from this lesson.
In the next lesson, we'll take a look at how we start treating this model.
So stay tuned for that.