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.
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.
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.
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 ℹ️
-
Run the following command in the project's root directory to run your web app.
python app/run.py -
Go to http://0.0.0.0:3001/
-
Choose a
jpg/jpegimage file to classify and clickUpload imageonce you've selected the file you want -
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. ℹ️
- You can run the cells in the
dog_app.ipynbnotebook in the standard Jupyter Notebook way.
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 appbin
| -run-black.sh: script to run black linting
| -run-black.sh: script to run flake8 linting
| -run-black.sh: script to run mypy lintingbottleneck_features
| Directory to store bottleneck features for thedog_appnotebook (empty in git)data
| -dog_names.json: json file containing names of dog breeds that can be classifiedhaarcascades
| -haarcascades_frontalface_alt.xml: model weights for human face recognition modelimages
| 13jpg/pngimage files used in thedog_appnotebook and READMErequirements
| -dog-linux-gpu.yml: GPUdog_appnotebook anaconda python environment export
| -dog-linux.yml: CPUdog_appnotebook anaconda python environment export
| -requirements-gpu.txt: GPUdog_appnotebook pip python environment export
| -requirements.txt: CPUdog_appnotebook pip python environment exportsaved_models
| -dogBreedXception.h5: re-trained imagenet model for dog breed classificationtest_images
| 7jpg/jpegimage files used to testing final CNN modelREADME.md: readme file.gitattributes: contains files managed by git-lfs.gitignore: file/folders to ignoreenvironment_dogApp.yml: flask app GPU anaconda python environment exportsetup.cfg: setup configs for flake8dog_app.ipynb: notebook used for exploration, dog breed classification model creation and training.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


