Skip to content

|| DSND - Classifying Dog Breeds Using Transfer Learning - Project 4 ||

Notifications You must be signed in to change notification settings

issaiass/Dog_Breed_Classifier

Repository files navigation

Udacity DSND Captstone Project - Dog Breed Classifier Using Transfer Learning

Project Overview and Motivation

This is the Captstone Project of the Udacity Data Science Nano Degree. In this project we will build a Dog Breed Multiclass Classifier using CNNs (Convolutional Neural Networks).

The consists of the next task: given an image, the algorithm must return an output of what it thinks to be... if is it an human, a dog or if any other image is interted (an error message will be displayed).

If a dog or human is predicted on the image it will return back the breed of the dog (even if it is human, just for fun, resembling the dog breed).

There are two datasets of dogs and humans. The dog dataset consists of 133 categories of dogs and with a total of 8351 images itself divided in 6680 training images, 835 validation images and 836 testing images for model metrics.

Table 1 - Description of the Dog Breed. 75% of breeds are class 92, 50% of class 59 and 25% of class 30 of breeds id

Graph 1 - Count of Dataset Distribution

Figure 1 - Dog Breed Classification Output

Figure 1 - Dog Breed Classification Output

On the notebook we will explore several tasks including a vanilla deep learning model and finally explore transfer learning methods and data agumentation for increase accuracy.

You can find the blog post here for more reading details.

Project Libraries Requirements

  • opencv-python==3.2.0.6
  • h5py==2.6.0
  • matplotlib==2.0.0
  • numpy==1.12.0
  • scipy==0.18.1
  • tqdm==4.11.2
  • keras==2.0.2
  • scikit-learn==0.18.1
  • pillow==4.0.0
  • ipykernel==4.6.1
  • tensorflow==1.0.0

File Descriptions

Six (6) folders are present on the repository.

  • bottleneck_features: it will contain VGG16 bottleneck features implemented in step 4 of the dog_app notebook.

  • haarcascateds: has the OpenCV default front face detector used on step 1 of the dog_app notebook.

  • images: it contains the dataset of images.

  • readme_images: the image of the overview and results that we are displaying in this readme.

  • requirements: contains all necessary files that will help you to get up and running you application if you want to clone the project and run on your computer, the data science nanodegree project folder or a cloud service like AWS.

  • saved_models: contain the files for the pretrained ResNet50, VGG16 and Inception models used in steps 2, 4 and 5 of the dog_app notebook.

There are also five (5) files related to the project:

  • .gitignore: if the project is downloaded and then migrated to the repository, this file will ensure that big data files remain on your local machine and will not get up to the remote repository.

  • dog_app.html: the output project in HTML format of the dog_app.ipynb.

  • dog_app.ipynb: The notebook of the datascience capstone project.

  • extract_bottleneck_features.py: contains functions for downloading pretrained models and for the transfer learning section.

  • REAMDE.md: this file as the information on motivation, file descriptions, how to run and results.

Project Instructions

Instructions

  1. Clone the repository and navigate to the downloaded folder.
git clone https://github.com/udacity/dog-project.git
cd dog-project
  1. Download the dog dataset. Unzip the folder and place it in the repo, at location path/to/dog-project/dogImages.

  2. 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.

  3. Donwload the VGG-16 bottleneck features for the dog dataset. Place it in the repo, at location path/to/dog-project/bottleneck_features.

  4. (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.

  5. (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 to requirements/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 to requirements/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 to requirements/dog-windows-gpu.yml):
    conda env create -f requirements/dog-windows.yml
    activate dog-project
    
  6. (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 to requirements/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 to requirements/requirements-gpu.txt):
    conda create --name dog-project python=3.5
    activate dog-project
    pip install -r requirements/requirements.txt
    
  7. (Optional) If you are using AWS, install Tensorflow.

sudo python3 -m pip install -r requirements/requirements-gpu.txt
  1. 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"
      
  2. (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"
  1. Open the notebook.
jupyter notebook dog_app.ipynb
  1. (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.

Major Parts of the Project in CNN

We first started with a small approach using a vanilla implementation of a neural network.

Figure 2 - Vanilla Convolutional Neural Network

Later we explored with a VGG16 pre-trained model without data augmentation method

Figure 3 - VGG16 Pretrained Model Using Transfer Learning Technique

Finally we used an Inception model to do transfer learning with data augmentation.

Figure 4 - Inception Model Using Transfer Learning Technique

Figure 5 - Data Augmentation Pipeline

Results

We can show below the image of the results of the model:

Figure 6 - First 3 results of the Dog Breed Classifier Output

Figure 8 - Last 3 results of the Dog Breed Classifier Output

Below you will se a table of the results of the training, validation and test datasets over different models and its metrics.

Table 2. Training Results using Different CNN Configurations.

- Vanilla CNN VGG16 Inception
Data Augmentation No Yes Yes
Training Loss 3.1555 7.451 0.0297
Training Accuracy 0.2394 0.5935 0.9949
Validation Loss 3.6421 8.1453 0.5334
Validation Accuracy 0.1538 0.4275 0.8582
Test Accuracy Metric 16.62% 42.7033% 83.0144%
📱 Having Problems?

License

About

|| DSND - Classifying Dog Breeds Using Transfer Learning - Project 4 ||

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published