Skip to content

A machine learning pipeline for classifying images of cats and dogs.

License

Notifications You must be signed in to change notification settings

oislen/CatClassifier

Repository files navigation

Cat Classification

Overview

This git repository contains code and configurations for implementing a Convolutional Neural Network to classify images containing cats or dogs. The data was sourced from the dogs-vs-cats Kaggle competition, and also from freeimages.com using a web scraper.

Three pretrained models were fine tuned to classify the images using PyTorch; AlexNet8, VGG16 and ResNet50.

Docker containers were used to deploy the application on an EC2 spot instances in order to scale up hardware and computation power.

Workflow

Analysis Results

The images were further normalised using rotations, scaling, zooming, flipping and shearing prior to the modelling training phase.

Generator Plot

The pretrained models were fine tuned across 10 epochs using stochastic gradient descent and cross entropy loss. Learning rate reduction on plateau and early stopping were implemented as part of training procedure.

Predicted Images

See the analysis results notebook for a further details on the analysis; including CNN architecture and model performance.

Master serialised copies of the fine tuned models are available on Kaggle:

Running the Application (Windows)

Anaconda

Create a local conda environment for the Cat Classifier app using anaconda:

conda create --name CatClassifier python=3.12 --yes
conda activate CatClassifier
pip install -r requirements.txt

Execute the webscrapers and model training pipeline using the following commands and the local conda environment:

:: run webscrapers
python webscrapers/prg_scrape_imgs.py --run_download_comp_data --run_webscraper
:: run model training pipeline
python model/prg_torch_model.py --run_model_training --run_testset_prediction

The model training and evaluation report can be opened with:

jupyter lab --ip=0.0.0.0 --allow-root "report/torch_analysis_results.ipynb"

Docker

The latest version of the Cat Classifier app can be found as a docker image on dockerhub here:

The image can be pulled from dockerhub using the following command:

docker pull oislen/cat-classifier:latest

The Cat Classifier app can then be started within a jupyter lab session using the following command and the docker image:

docker run --name cc --shm-size=512m --publish 8888:8888 -it oislen/cat-classifier:latest