Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Cat and Dog Classification Using CNN: Project Objective

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Cat and dog classification using CNN

Project Objective:

Build a CNN model that classifies the given pet images correctly into dog and cat images.
The project scope document specifies the requirements for the project “Pet Classification Model Using
CNN.” Apart from specifying the functional and non-functional requirements for the project, it also
serves as an input for project scoping.
Project Description and Scope:
You are provided with a collection of images of pets, that is, cats and dogs. These images are of different
sizes with varied lighting conditions and they should be used as inputs for your model.
You are expected to write the code for CNN image classification model using TensorFlow that trains on the
data and calculates the accuracy score on the test data.
Starting the Projects:
Convolutional Neural Network (CNN) is an algorithm taking an image as input then assigning weights
and biases to all the aspects of an image and thus differentiates one from the other. Neural networks
can be trained by using batches of images, each of them having a label to identify the real nature of
the image (cat or dog here). A batch can contain few tenths to hundreds of images. For each image,
the network prediction is compared with the corresponding existing label, and the distance between
network prediction and the truth is evaluated for the whole batch. Then, the network parameters are
modified to minimize the distance and thus the prediction capability of the network is increased. The
training process continues for every batch similarly.

Dogs vs. Cats Prediction Problem

The main goal is to develop a system that can identify images of cats and dogs. The input image will
be analysed and then the output is predicted. The model that is implemented can be extended to a
website or any mobile device as per the need. The dataset contains a set of images of cats and dogs.
Cat and dog classification using CNN
Our main aim here is for the model to learn various distinctive features of cat and dog. Once the
training of the model is done it will be able to differentiate images of cat and dog.

Import Libraries
NumPy- For working with arrays, linear algebra.

2. Pandas – For reading/writing data

3. Matplotlib – to display images

4. TensorFlow Keras models – Need a model to predict right !!

5. TensorFlow Keras layers – Every NN needs layers and CNN needs well a couple of layers.

CNN does the processing of Images with the help of matrixes of weights known as filters. They detect
low-level features like vertical and horizontal edges etc. Through each layer, the filters recognize
high-level features.

We first initialize the CNN


Cat and dog classification using CNN
For compiling the CNN, we are using adam optimizer.
Adaptive Moment Estimation (Adam) is a method used for computing individual learning
rates for each parameter. For loss function, we are using Binary cross-entropy to compare the
class output to each of the predicted probabilities. Then it calculates the penalization score
based on the total distance from the expected value.
Image augmentation is a method of applying different kinds of transformation to original
images resulting in multiple transformed copies of the same image. The images are different
from each other in certain aspects because of shifting, rotating, flipping techniques. So, we
are using the Keras ImageDataGenerator class to augment our images.

To check your images with


ImageDataGenerotor Model

We need a way to turn our images into batches of data arrays in memory so that they can be fed to the
network during training. ImageDataGenerator can readily be used for this purpose. So, we import this
class and create an instance of the generator. We are using Keras to retrieve images from the disk with
the flow_from_directory method of the ImageDataGenerator class.

Convolution
Cat and dog classification using CNN
Convolution is a linear operation involving the multiplication of weights with the input. The
multiplication is performed between an array of input data and a 2D array of weights known
as filter or kernel. The filter is always smaller than input data and the dot product is
performed between input and filter array.

Activation

The activation function is added to help ANN learn complex patterns in the data. The main
need for activation function is to add non-linearity into the neural network.

Pooling

The pooling operation provides spatial variance making the system capable of recognizing an
object with some varied appearance. It involves adding a 2Dfilter over each channel of the
feature map and thus summarise features lying in that region covered by the filter.

So, pooling basically helps reduce the number of parameters and computations present in the
network. It progressively reduces the spatial size of the network and thus controls overfitting.
There are two types of operations in this layer: Average pooling and Maximum pooling.
Here, we are using max pooling which according to its name will only take out the maximum
from a pool. This is possible with the help of filters sliding through the input and at each
stride, the maximum parameter will be taken out and the rest will be dropped.

The pooling layer does not modify the depth of the network unlike in the convolution layer.

Fully Connected
Cat and dog classification using CNN
The output from the final Pooling layer which is flattened is the input of the fully connected layer.

The Full Connection process practically works as follows:

The neurons present in the fully connected layer detect a certain feature and preserves its value
then communicates the value to both the dog and cat classes who then check out the feature and
decide if the feature is relevant to them.

We are fitting our model to the training set. It will take some time for this to finish.
Cat and dog classification using CNN

It is seen that we have 0.9750 accuracies on our training set.


We can predict new images with our model by predict_image function where we have to
provide a path of new image as image path and using predict method. If the probability is
more than 0.5 then the image will be of a dog else of cat.
Cat and dog classification using CNN

Features Provided:

We can test our own images and verify the accuracy of the model.

We can integrate the code directly into our other project.

We can extend the project to different entities by just finding the suitable dataset, change the
dataset and train the model accordingly.

You might also like