Skip to content

0zero/DogBreedClassifier

Repository files navigation

Dog Breed Classifier

Project Brief

This project forms the basis of learning about Convolutional Neural Networks and Transfer Learning. The aim is to use transfer learning to create a dog breed classification model capble of taking an image as input and predicting what dog breed the image resembles.

The model is trained and evaluated in dog_app.ipynb and can be used in web-app form by following the instructions below.

Summary of findings

Using the technique of transfer learning, whereby a model trained for solving one problem is applied to a different but related problem, I have taken the Xception CNN model pre-trained on ImageNet and retrained the final layers with 6680 images of various dogs to classify dog breeds from user provided images.

The final model achieves a test accuracy of ~$82,%$ and the training and validation accuracy and loss can be seen in Figure 1 below.

model_eval

Fig.1 - Xception model train and validation accuracy and loss.


In the corresponding web-app, a user can upload an image file and check what dog breed the model predicts as seen in Figure 2.

dogapp

Fig.2 - Webapp example of model correctly predicting the breed as Pomenarian.

Using the model

Environment Setup Instructions:

I've used Anaconda with Python 3.9.13 to create the environment for this work. You can use the environment_dogApp.yml file to create the environment locally using:

conda env create -f environment_dogApp.yml

You can then activate it with

conda activate tf-gpu

This will install various Python packages including tensoflow-gpu, keras, sklearn, flask and their dependencies.

ℹ️ you might need to use the conda-forge when creating this environment ℹ️

App run Instructions:

  1. Run the following command in the project's root directory to run your web app. python app/run.py

  2. Go to http://0.0.0.0:3001/

  3. Choose a jpg/jpeg image file to classify and click Upload image once you've selected the file you want

  4. Wait for the app to return the model's prediction and see if you agree with its findings.

ℹ️ The app can take a bit of time to get going the first time around. Caching may improve this. ℹ️

Notebook run Instructions:

  1. You can run the cells in the dog_app.ipynb notebook in the standard Jupyter Notebook way.

⚠️ This notebook carries out convolutional neural network training and requires a good graphics card with lots of memory. I've also not included the training images to this git repository due to storage constraints. If you want to get this data, please drop me a message. ⚠️

File descriptions

Below we have a brief description of the directories and the files they contain.

  • app
     | - template
     | --- index.html: main page of web app
     | - detector_models.py: Detector model classes
     | - dog_classifier.py: Dog breed classifier class
     | - helpers.py: Helper functions
     | - run.py: Flask file that runs app
  • bin
     | - run-black.sh: script to run black linting
     | - run-black.sh: script to run flake8 linting
     | - run-black.sh: script to run mypy linting
  • bottleneck_features
     |    Directory to store bottleneck features for the dog_app notebook (empty in git)
  • data
     | - dog_names.json: json file containing names of dog breeds that can be classified
  • haarcascades
     | - haarcascades_frontalface_alt.xml: model weights for human face recognition model
  • images
     |    13 jpg/png image files used in the dog_app notebook and README
  • requirements
     | - dog-linux-gpu.yml: GPU dog_app notebook anaconda python environment export
     | - dog-linux.yml: CPU dog_app notebook anaconda python environment export
     | - requirements-gpu.txt: GPU dog_app notebook pip python environment export
     | - requirements.txt: CPU dog_app notebook pip python environment export
  • saved_models
     | - dogBreedXception.h5: re-trained imagenet model for dog breed classification
  • test_images
     |    7 jpg/jpeg image files used to testing final CNN model
  • README.md: readme file
  • .gitattributes: contains files managed by git-lfs
  • .gitignore: file/folders to ignore
  • environment_dogApp.yml: flask app GPU anaconda python environment export
  • setup.cfg: setup configs for flake8
  • dog_app.ipynb: notebook used for exploration, dog breed classification model creation and training.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

About

Convolutional Neural Networks and Transfer Learning are used to classify dog breeds

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages