https://github.com/tyler-hilbert/cat_vs_dog_image_classification
Compares KNN, HOG/SVM and CNN for classifying images as cat or dog
https://github.com/tyler-hilbert/cat_vs_dog_image_classification
computer-vision
Last synced: about 1 year ago
JSON representation
Compares KNN, HOG/SVM and CNN for classifying images as cat or dog
- Host: GitHub
- URL: https://github.com/tyler-hilbert/cat_vs_dog_image_classification
- Owner: Tyler-Hilbert
- Created: 2020-12-10T10:45:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-19T03:00:20.000Z (over 4 years ago)
- Last Synced: 2024-12-29T07:13:36.168Z (over 1 year ago)
- Topics: computer-vision
- Language: Python
- Homepage:
- Size: 1020 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cat vs Dog Image Classifier
Compares the accuracy of KNN, HOG/SVM and CNN for classifying an image as cat or dog.
# Conclusion
A CNN is the best approach to this dataset with a 91% accuracy.
Neither the KNN or HOG/SVM performed well enough to be considered useable for this dataset as they barely did better than a random guess.
# Analysis of Each Algorithm (best to worst)
## CNN (Convolutional Neural Network)
CNN written using Pytorch.
### CNN Results
AlexNet: 91%
11 Convolutional Layers + ReLU + Batch Normalization: 89.5%
6 Convolutional Layers + ReLU + Batch Normalization: 83%
3 Convolutional Layers + ReLU + Batch Normalization: 81%

### CNN Setup Instructions
[put the train data set from this link - https://www.kaggle.com/c/dogs-vs-cats/data - ](https://www.kaggle.com/c/dogs-vs-cats/data) into the following directories:
dataYouTubeFormat/train/cat
dataYouTubeFormat/train/dog
dataYouTubeFormat/test/cat
dataYouTubeFormat/test/dog
Some hyperparameters can be set under `Constants` in CNN_CatVsDog.py, while others will need to be set in the `ConvNN` class or in the following lines of code:
```
transformer = transforms.Compose([
transforms.Resize( (150,150) ), # Is this the correct size?
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
```
## HOG / SVM (Histogram of Oriented Gradients / Linear SVM)
HOG / SVM written using scikit-learn.
### HOG / SVM Results
The accuracy of the HOG / SVM algorithm consistently got around a 60% accuracy even with many different hyperparameters and training set sizes.
### KNN Setup Instructions
[put the train data set from this link - https://www.kaggle.com/c/dogs-vs-cats/data - into the directory data/](https://www.kaggle.com/c/dogs-vs-cats/data)
Hyperparameters for the SVM can be set under `Constants` in HOG-CatDog.py and the following 2 lines for the bin size:
```
fd = fd.round(1)
...
for i in np.arange(0, 1.1, 0.1).round(1).tolist():
```
Hyperparameters for the HOG need to be set in the following line of code within HOG-CatDog.py:
`fd, hogImage = hog(image, orientations=64, pixels_per_cell=(32, 32), cells_per_block=(1, 1), visualize=True, multichannel=True)`
## KNN (k-nearest neighbors)
KNN written from scratch using Python3.
### KNN Results
The accuracy was around 50%-60%.
KNN was tested for k = 3, 7, 11, 23, 45, 101, 201 and 301.
### KNN Setup Instructions
[put the train data set from this link - https://www.kaggle.com/c/dogs-vs-cats/data - into the directory data/](https://www.kaggle.com/c/dogs-vs-cats/data)
Hyperparameters can be set under `Constants` in knn_catVsDog.py