Skip to content

eswar3/CNN-Image-classifier

Repository files navigation

Dog-breed Classifier

Project Overview

It is Convolutional Neural Networks (CNN) project in the Deep Learnig Nanodegree. In this project, I learnt how to build a pipeline that can be used to process real-world, user-supplied images. Given an image of a dog, the algorithm will identify an estimate of the canine’s breed. If supplied an image of a human, the code will identify the resembling dog breed.

Sample Output

In the project I have learnt to build state of art CNN models using tensorflow framework and also how to use pre-trained models such as

- VGG-19 
- ResNet-50 
- Inception 
- Xception 

and apply transfer learning techniques to train on our data. As you will observe wn this notebook, it made a significant difference compared to training model from scratch

Project 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

Project Instructions

Instructions

  1. Clone the repository and navigate to the downloaded folder.
git clone https://github.com/eswar3/CNN-Image-classifier.git
cd CNN-Image-classifier
  1. Download the dog dataset. Unzip the folder and place it in the repo, at location path to CNN-Image-classifier/data/dog_images.

  2. Download the human dataset. Unzip the folder and place it in the repo, at location pathto CNN-Image-classifier/data/lfw. If you are using a Windows machine, you are encouraged to use 7zip to extract the folder.

  3. Download the VGG-16 bottleneck features for the dog dataset. Place it in the repo, at location path to CNN-Image-classifier/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_breed_classifier_CNN_Transfer_Learning.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.