Capstone project - recognition of dog breeds
Introduction
This is an educational project where I use Convolutional Neural Networks to detect dog breeds on pictures. Besides its educational purpost it is also entertaning, because you can also fill in pictures of humans and it will return the dog breed the person looks like.
Main Questions
The main question (or better task) of this project was to understand how Convolutional Neural Networks can be implemented in python, how keras as libary can be used and if it is possible to detect dog breeds with relatively small time consumption.
Used Libaries
The following libaries are used in the project:
- sklearn
- keras
- numpy
- glob
- random
- cv2
- matplotlib
- tqdm
- PIL
- extract_bottleneck_features
Architecture
The project is in a JupiterNotebook but within this notebook it is split in 8 steps:
- Step 0: Import Datasets
- Step 1: Detect Humans
- Step 2: Detect Dogs
- Step 3: Create a CNN to Classify Dog Breeds (from Scratch)
- Step 4: Use a CNN to Classify Dog Breeds (using Transfer Learning)
- Step 5: Create a CNN to Classify Dog Breeds (using Transfer Learning)
- Step 6: Write your Algorithm
- Step 7: Test Your Algorithm
Besides the jupiter notebook, there are several other data structures used which are explained in the Installation Instruktions below.
Results
The result is a model that is able to classify pictures by dog breeds. If you fill in a picture of a human or a dog, it is able to detect if it is a human or a dog and in the second step it assignes the picture to a dog breed. I tested the output with some pictures from picabay.com (free to use) and the results are quite good.
Challenges and Learnings
In this project I had to learn CNN from zero. I did not have any knowledge about neuronal networks but by reading articles on Wikipedia, Readme's from keras and some blogposts about the topic. I gained some knowledge and were able to generate a CNN that classifies dogs to its breeds.
Installation Instructions
- Clone the repository and navigate to the downloaded folder.
git clone https://github.com/udacity/dog-project.git
cd dog-project
-
Download the dog dataset. Unzip the folder and place it in the repo, at location
path/to/dog-project/dogImages
. -
Download the human dataset. Unzip the folder and place it in the repo, at location
path/to/dog-project/lfw
. If you are using a Windows machine, you are encouraged to use 7zip to extract the folder. -
Download the VGG-16 bottleneck features for the dog dataset. Place it in the repo, at location
path/to/dog-project/bottleneck_features
. -
(Optional) If you plan to install TensorFlow with GPU support on your local machine, follow the guide to install the necessary NVIDIA software on your system. If you are using an EC2 GPU instance, you can skip this step.
-
(Optional) If you are running the project on your local machine (and not using AWS), create (and activate) a new environment.
- Linux (to install with GPU support, change
requirements/dog-linux.yml
torequirements/dog-linux-gpu.yml
):
conda env create -f requirements/dog-linux.yml source activate dog-project
- Mac (to install with GPU support, change
requirements/dog-mac.yml
torequirements/dog-mac-gpu.yml
):
conda env create -f requirements/dog-mac.yml source activate dog-project
NOTE: Some Mac users may need to install a different version of OpenCV
conda install --channel https://conda.anaconda.org/menpo opencv3
- Windows (to install with GPU support, change
requirements/dog-windows.yml
torequirements/dog-windows-gpu.yml
):
conda env create -f requirements/dog-windows.yml activate dog-project
- Linux (to install with GPU support, change
-
(Optional) If you are running the project on your local machine (and not using AWS) and Step 6 throws errors, try this alternative step to create your environment.
- Linux or Mac (to install with GPU support, change
requirements/requirements.txt
torequirements/requirements-gpu.txt
):
conda create --name dog-project python=3.5 source activate dog-project pip install -r requirements/requirements.txt
NOTE: Some Mac users may need to install a different version of OpenCV
conda install --channel https://conda.anaconda.org/menpo opencv3
- Windows (to install with GPU support, change
requirements/requirements.txt
torequirements/requirements-gpu.txt
):
conda create --name dog-project python=3.5 activate dog-project pip install -r requirements/requirements.txt
- Linux or Mac (to install with GPU support, change
-
(Optional) If you are using AWS, install Tensorflow.
sudo python3 -m pip install -r requirements/requirements-gpu.txt
-
Switch Keras backend to TensorFlow.
- Linux or Mac:
KERAS_BACKEND=tensorflow python -c "from keras import backend"
- Windows:
set KERAS_BACKEND=tensorflow python -c "from keras import backend"
- Linux or Mac:
-
(Optional) If you are running the project on your local machine (and not using AWS), create an IPython kernel for the
dog-project
environment.
python -m ipykernel install --user --name dog-project --display-name "dog-project"
- Open the notebook.
jupyter notebook dog_app.ipynb
- (Optional) If you are running the project on your local machine (and not using AWS), before running code, change the kernel to match the dog-project environment by using the drop-down menu (Kernel > Change kernel > dog-project). Then, follow the instructions in the notebook.
NOTE: While some code has already been implemented to get you started, you will need to implement additional functionality to successfully answer all of the questions included in the notebook. Unless requested, do not modify code that has already been included.