Classifying a cat or dog image sounds very easy, but nobody could have a 100% accuracy model nowadays.
There is a famous meme about AI, which is that AI identifies a cat as a dog. In this project,
I ended up with an 88% accuracy model in my testing dataset. The model is an example of how I created a Convolutional Neural Network model.
Dataset
This is a balanced dataset. There are 4000 cat and 4000 dog images in the training dataset and
1000 cat and 1000 dogs images in the testing dataset. The total size is just 232 MB, but
there are still many things I need to do in order to reduce the size.
CNN and ANN Layers
Due to my laptop performance, I only chose to use 32 feature filters and changed the
size of my images into 64*64. Also, I selected my feature detector size as a 3*3 square and
my pooling size as a 2*2 square with a stride of 2. To improve the accuracy, I added two
convolutional layers.
After adding the convolutional layers, I added one artificial neural network layer.
To prevent overfitting, I added one dropout layer with a 0.1 dropout rate. Also,
because classifying images is much more complicated, I used 128 nodes in this case.
In the end, I used the adam optimizer, a famous stochastic gradient descent algorithm. Because
I only have two classes, binary cross-entropy was used as the loss function.
Data Augmentation
Even though I have thousands of pictures, I still want to have more data.
Three techniques were used here, shear, zoom and flip. I also rescaled the images in this step.
Model Training and Saving
The training process still takes several hours even I tried my best to minimize this process.
The model has an 88% accuracy, and I don't want to lose this model after several hours of the training
process. The model was saved.
Model Testing
I used some wired images in my model. Most of them are correct, except the meme cat picture.
It's very hard to believe that my model predicted a wrong result, but after testing other cat
images, it occurred to me that my model really did a wrong prediction. Anyway, the accuracy of
this model is just 88%. This is not a bad model, but it's not a perfect model.
Final Thoughts
I could've improved my model by setting a higher resolution, more nodes, and more epochs. Also, I could've selected more images, applied the grid search method, and some other techniques. While, due to my laptop performance, I don't want to spend several days training my model. Long way to go as a data scientist.
Software used: Python, Pycharm
Packages used: Tensorflow, Keras,