‫Now, this is the architecture we are going to use for our CNN model.
‫If you remember last time when we ran ANN model on this problem, we used this side of the network.
‫We first use flatten layer, then dense layered with 300 neuron, then dense layer with 100 neurons
‫and then the output layer.
‫We are going to add CNN layers before this.
‫So this is our input, 28 by 28 pixel cross one.
‫So 28 pixels as width, 28 pixels as height and one as the channel.
‫We are going to use a filter size of three by three with the shride of one.
‫And then this will be our convolutional layer.
‫Since we are using filter size of three by three.
‫And we are also using a padding as valid.
‫We are ignoring one pixel from each side.
‫Since our padding is valid
‫So the convolutional layer, we are going to get this 26 by 26 into 32, we are going to use 32 different
‫filters for this convolutional layer.
‫After this, we are going to use to use Max pooling
‫So finally, after this corn layer, we are going to get 13 by 13 into 32 cells in our pooling layer.
‫Now, we have to add some dense layer as well.
‫So we have to convert this 3D object into one dimensionality.
‫So we are using flatten layer.
‫Then we are going to use to dense layer.
‫First one with 300 neuron.
‫And next one with hundred neurons.
‫And then we are going to use an output layer with 10 neurons.
‫Since we have to identify ten different classes, the code is almost similar.
‫First, we have to create a model object.
‫Then we are going to add the convolutional layer.
‫We'll write model, dot, add and then keras dot layers, dot com, 2d.
‫And as parameters, we want to do filters.
‫We want to have our filter of size three by three.
‫So we have to provide
‫Kernel size has three comma three.
‫If you want a filter size of four by four you can write four comma four
‫By default the stride value is one.
‫We are going to use the same.
‫And we are going to use padding as valid.
‫The activation is always relu.
‫And the input shape is 28.
‫Cross 28.
‫Cross one.
‫If you are dealing with any Colored images, you have to give values for channel as well.
‫So for colored images, this should be three.
‫This should be the height, width ‫and then the number of channels.
‫So this is a work on layer for our pulling layer.
‫We can edit using this syntax model dot add then Keraf dot layers dot max pulling 2D.
‫And then here you have to give the dimensions of your window.
‫We are going to use deceptive.
‫Field of two cross two.
‫That's why we are giving two comma two as a parameter.
‫After this, we want to convert our three dimensional matrix into one dimensional matrix.
‫So we have to use flatten and after flatten.
‫We can use our dense layers as we did in ANN.
‫So we are adding another layer with 300 neurons.
‫And then another layer with 200 neurons.
‫And for both of these layers, we want our activation function to be of RELU.
‫And the next layer is our output layer.
‫We want to classify 10 different categories.
‫That's why we are using 10 neurons.
‫And the activation is softmax activation because this is a classification problem.
‫Now, let's run this.
‫No, similar to last time.
‫We can use Dot summary method to get details.
‫Of our model architecture.
‫Here you can get information of all the layers or what is the shape of those layers and the number of parameters
‫that you are going to train.
‫Using this model architecture,
‫now important thing here you can notice is that the number of parameters we are going to train is in
‫millions.
‫So in this dense layer, we have around one point six million parameters to train.
‫Now, if we have not used Max fulling layer two, this would have been around four million or five million
‫neurons.
‫So so using max pooling has significantly reduced the number of parameters that we are going to train
‫in the next lecture.
‫We will try to train a model without a pooling layer.
‫And there we can clearly see the difference in number of parameter and the execution time in the models
‫with the pulling layer and without the pullying layer.
‫The next step is to compile the model now since we have exclusive multi label classification problem.
‫We are going to use a sparse, categorical and Cross and Groppi and we want to use Optimizer as a study.
‫So class state, Verdean descent.
‫And we want to calculate the accuracy.
‫Since we are doing the classification problem, it's compiled this model.