15

Train an Image Classifier using Keras.

 4 years ago
source link: https://mc.ai/train-an-image-classifier-using-keras/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I have used sequential API to stack multiple layers of convolution, max-pooling layers with a flatten as well as some dense layers.

I strongly recommend you to first build your basics of the working of CNN and get used to all the terminologies that are common in CNNs.

Let’s look at the architecture in detail.

The first layer is a Convolutional Layer that will take an image as an input of size (300 * 300* 3). Then using the activation argument we can apply different activation functions like ‘relu’, ‘tanh’, ‘sigmoid’, ‘softmax’ e.t.c, here I have applied ‘relu’ activation function.

Let’s talk about the number and size of the filters in the first layer we have used.

Through a Kernel size parameter, we could set the size of the filter as we have set it as (5*5), and using filters parameter we could set the number of filters we want to use and in our architecture, it is set to 32.

Now the second layer is a Maxpooling layer that can be applied simply by calling the MaxPooling2D function.

Similarly the third and the fourth layers are the Convolutional and the Maxpooling layers respectively.

Now we’ll flatten out the feature map using flatten function so that we could use those extracted features as an input to the Multi-Layer Perceptron for the classification.

After flattening out the feature map I have used 3 hidden layers that have 128, 64, and 32 number of neurons respectively.

You could build these hidden layers easily with the help of the Dense() method, also you could pass the activation function that you want to apply.

In the end, the last layer also called an Output layer has 2 neurons that give out the likelihood of two classes.

Check that I have used the Softmax activation function in the last layer as it converts the final information in the probability distribution for multiple classes.

Now let’s see the summary of our model using a summary() method.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK