Skip to content

dingyif/udacity_dog_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dog Breed Classifier App in Pytorch

This is the repository for second project of Udacity Deep Learning Nanodegree The code is implemented with Pytorch librabry. Udacity Provided the Starter Code and the original repo is HERE.

Project Overview

Welcome to the Convolutional Neural Networks (CNN) project in the AI Nanodegree! In this project, you will learn how to build a pipeline that can be used within a web or mobile app to process real-world, user-supplied images. Given an image of a dog, your 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

Along with exploring state-of-the-art CNN models for classification and localization, you will make important design decisions about the user experience for your app. Our goal is that by completing this lab, you understand the challenges involved in piecing together a series of models designed to perform various tasks in a data processing pipeline. Each model has its strengths and weaknesses, and engineering a real-world application often involves solving many problems without a perfect answer. Your imperfect solution will nonetheless create a fun user experience!

Brief Summary of what I did:

- Build Own CNN using Pytorch with the structure below.

  1. Convolutional Layer
    (conv1) nn.Conv2d(3,16,kernel_size= 3,stride=1,padding=1)
    (relu) nn.ReLU()
    (pool1) nn.MaxPool2d(2,2)
    (conv2) nn.Conv2d(16,32,kernel_size=3,stride=1,padding=1)
    (relu) nn.ReLU()
    (pool2) nn.MaxPool2d(2,2)
    (conv3) nn.Conv2d(32,64,kernel_size=3,stride=1,padding=1)
    (pool3) nn.MaxPool2d(2,2)
  2. Fully Connected Layer
    Flatten the image
    (fc1) nn.Linear(282864,1024)
    (relu)nn.ReLU()
    (dropout) nn.Droupout(0.2)
    (fc2) nn.Linear(1024,133)

For Loss and Optimizer choices:

I choose the Loss to be CrossEntropy Loss and SGD with momentum as my Optimizer. The random guess of prediction is 0.75%, and with only 10 epochs of training my model reached performance of 11%. I believe with long enough epochs, this will reach a decent accurarcy.

Transfer Learning

I selected the VGG16 pertrained framework and changed the last layer of 1000 into 133 classes, and with just 8 epochs of retrain the classificaiton layer the accuracy of the model reached 85% on test dataset. It performed extremely well compared to the CNN from scratch.

Model Evalution:

I randomly selected few photos from website to test the model. Here're some results:

dog1 dog2 dog3 Human1 Human2

Suggestions from Udacity:

  1. Consider using transforms.Resize(256) and transforms.CenterCrop(224) instead of RandomResizedCrop for train dataset also. The reason is RandomResizedCrop crop the image from random (centre, corner etc) so it might miss the face of dogs
  2. CNN from scratch:
    • Consider using Batch Normalization after each convolution layer (number of conv layer = number of batch normlization layer)
    • Consider using ELU or LEAKY_RELU activation function
    • Consider adding weight initialization parameter in conv2d operation
    • Set Dropout rate between 0.4-0.5
  3. Transfer Learning:
    • Try experiment with Inception and Xception net which is more power than VGG and Resnet

Project Instructions

Instructions

  1. Clone the repository and navigate to the downloaded folder.

    	git clone https://github.com/udacity/deep-learning-v2-pytorch.git
    	cd deep-learning-v2-pytorch/project-dog-classification
    

NOTE: if you are using the Udacity workspace, you DO NOT need to re-download the datasets in steps 2 and 3 - they can be found in the /data folder as noted within the workspace Jupyter notebook.

  1. Download the dog dataset. Unzip the folder and place it in the repo, at location path/to/dog-project/dogImages. The dogImages/ folder should contain 133 folders, each corresponding to a different dog breed.
  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. Make sure you have already installed the necessary Python packages according to the README in the program repository.
  4. Open a terminal window and navigate to the project folder. Open the notebook and follow the instructions.

About

About Udacity (Project 2) Dog Breed Classifier App with PyTorch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published