Dogs vs Cats — A Project in Exploration Data Analysis and Machine Learning
By: Atanda Rilwan Olaitan
Tags: Neural Networks, Convolutional Neural Net, Machine Learning, Exploratory Data Analysis, Deep Learning

As a pet lover, the challenge from Kaggle about recognizing whether the animal in the picture is a cat or a dog has caught my attention. The “Dogs vs Cats” challenge provides a dataset about pictures of cats and dogs. This image recognition problem then asks participants to build an algorithm to classify whether pictures from the uncategorized test data contain either a dog or a cat. Although this challenge is easy to be done with human eyes, it is hard for computers to classify. In this report, I will explore the data from Kaggle, train and compare multiple ML models, and articulate why I choose my final model at the end.

Dataset:

I extracted the dogs-vs-cats dataset from Kaggle, with 2 zip files: “train.zip” and “test1.zip”.

The “train.zip” refers to training data, which contains the pictures of dogs/cats, picture ids, and labels — either a dog or a cat is in the picture. For example, a cat picture in the training data may have the name “cat.1024.jpg”, as shown below.

“cat.1024.jpg” in “train.zip” from Kaggle dataset

The “test1.zip” refers to testing data, which contains the pictures of dogs/cats, picture ids, but not labels, and is used to test models and submit to Kaggle challenge. For example, a cat picture in the testing dataset may have the name “1024.jpg”, as shown below.

“1024.jpg” in “test1.zip” from Kaggle dataset

Data Collection

Here are a few random dog photos from the dogs-vs-cat dataset:

9 dog pictures with their own sizes

And here are a few random cat photos from the dogs-vs-cat dataset:

9 cat pictures with their own sizes

In the code, dogs are encoded as 1, and cats are encoded as 0. Here’s an example of the data frame:

All entries in the data frame are non-null, thus there’s no need to further clean the null data.

From the 25000 entries of data in the training dataset, we have 125000 cats and 125000 dogs, indicated in the picture below.

Thus, by comparing the performance of Model 1 with and without dropout regularization, we can tell that the overall accuracy does not improve much, but the overfitting has been reduced or delayed.

Discussion

For the three models with different amounts of convolution layers (the combination of Conv2D and MaxPool2D layers), the accuracies of the models are as follows:

Model 1 has an accuracy of 0.5369 (one convolution layer).

Model 2 with an accuracy of 0.7189 (two convolution layers).

Model 3 has an accuracy of 0.7076 (three convolution layers).

Model 1 with dropout regularization has an accuracy of 0.5164 (one convolution layer).

From the results above, we can tell that there’s an increase in accuracies between one and two convolution layer(s) but not in accuracies between two and three convolution layers. Thus, there’s no overall pattern between the number of layers and the accuracy of the model.

Besides, by adding dropout regularization to Model 1, the accuracy is not increased much. However, the obvious overfitting behavior after epoch 3 for Model 1 has been reduced or delayed to a great extent. For further exploration and optimization, a larger dropout rate after the convolution layer could be considered.

In order to make the model most accurate, I choose Model 3 as my final model. For further overfitting problems, dropout regularization or image augmentation could be used.

Github Repo:

https://github.com/rilwanatanda/Dogs-vs-Cats