-
Clone this repository.
git clone https://github.com/ranamahmud/dog-breed-classifier-udacity-capstone.git
-
Install conda
pip install conda
-
Create and activate conda environment.
conda create --name dog-project python=3.7
conda activate dog-project
- Python used 3.7. You can use python 3.7+.
- Install the python packages using requirements.txt using
pip3 install -r requirements.txt
-
Cd into web app directory.
cd webapp
-
To run in the Windows operating system use the following command:
set FLASK_APP=app.py
flask run
- To run on Linux use the following command:
export FLASK_APP=app.py
flask run
- The app will be running on http://127.0.0.1:5000/
requirements.txt - Python Package List
report.html - dog_app.ipynb in html format.
dog_app.ipynb - jupyter notebook of dog breed classifier.
webapp - web app folder.
images - folder of image files for the markdown file.
Welcome to the Dog Breed Classifier using Convolutional Neural Networks (CNN) capstone project in the Data Scientist Nanodegree! In this project, I've built a pipeline that was used in a web app to process real-world, user-supplied images. Given an image of a dog, this web app will identify an estimate of the dog’s breed. If supplied with an image of a human, the app will identify the resembling dog breed.
For our web app, we've to write an algorithm that accepts a file path to an image and first determines whether the image contains a human, dog, or neither. Then,
-
If a dog is detected in the image, return the predicted breed.
-
If a human is detected in the image, return the resembling dog breed.
-
If neither is detected in the image, provide an output that indicates an error.
- Build Humans and Dog detectors from the image.
- Create a CNN to Classify Dog Breeds (from Scratch)
- Use a CNN to Classify Dog Breeds (using Transfer Learning)
- Create a CNN to Classify Dog Breeds (using Transfer Learning)
- Choose the best CNN model for classification.
- Write your Algorithm to detect dog breed or resembling dog breed or return an error.
- Test the Algorithm.
- Export the best model.
- Build a flask web app using the model.
- Test the model.
The expected solution will be a web application that can do the following things
- Users can upload an image from the computer.
- If a dog is detected in the image, it'll show the predicted breed.
- If a human is detected in the image, it'll show the resembling dog breed.
- If neither is detected in the image, it'll show an error.
- If the prediction fails, it will show an error.
We'll use test accuracy as a measure of model performance. Based on the highest test accuracy we'll choose a CNN model for building the web app and algorithm.
There are 133 total dog categories. There are 8351 total dog images.
There are 6680 training dog images. There are 835 validation dog images. There are 836 test dog images.
There are 13233 total human images.
I've used OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images.
100.0 percent of the first 100 images in human_files have a detected human face. 11.0% percent of the first 100 images in dog_files have a detected human face
I've used a pre-trained ResNet-50 model to detect dogs in images.
0.0 percentage of the images in human_files_short have a detected dog. 100.0 percentage of the images in dog_files_short have a detected dog
CNN from scratch has a test performance of 3.1100%.
THE pre-trained VGG-16 CNN model has a test accuracy of 41.5072%.
CNN to Classify Dog Breeds using Resnet50(using transfer Learning) has a test accuracy of 79.6651.
Among the 3 models, CNN to Classify Dog Breeds using Resnet50 has the best performance. We'll use it to build our Algorithm for the web app.
Welsh Springer Spaniel
Brittany
From the above two images, we can see that dog breed pairs are often similar and difficult to differentiate.
source: Ramiz Dedaković @ramche unsplash
Photo by Ramiz Dedaković on Unsplash
- This web app uses dog_detector() for dog detection and face_detector() for face detection.
- For dog breed detection CNN model with a pre-trained Resnet50 model is used.
- In the flask web app we've used predict_human_dog() function to predict dog breed or resembling dog breed.
- User uploads an image file on the app home page.
- After uploading the user clicks on the Predict button.
- When a dog breed is detected it shows the dog breed information.
- When a human face is detected it shows the human face resembling dog breed.
- For anything else it shows error message.
- Implementation of the file upload in the flask website using ajax was difficult.
- Testing the final algorithm was very much interesting.
One aspect of the implementation we can improve is making the human face detector more robust so that it can detect human when the human face is not visible. We can use a pre-trained facenet model or other face detectors from open cv to detect humans. Which might improve our web app and algorithm.