Giter VIP home page Giter VIP logo

p4's Introduction

Table of Contents

  1. Project Overview
  2. Problem Statement
  3. Data Exploration & Visualization
  4. Metrics
  5. Installation
  6. File Descriptions
  7. Results
  8. Licensing, Authors, and Acknowledgements
Please look at Jupyter notebook in this repo if you have any unanswered questions.

Project Overview

When humans look at images, we take for granted that our brain can process the image and decide what the image contains fairly quickly. The goal of my CNN and CNNs in general (at least for image recognition and classification) is to replicate this process algorithmically and to teach our computer how to do this. With this in mind, the aim of this project was to define and train a Convolutional Neural Network (CNN) that could predict dog breeds from images of dogs. The final CNN used in the app was built using transfer learning from Google's InceptionV3 CNN, with additional training on dog-specific images provided by udacity.

Problem Statement

Using images provided by udacity, my main objective was to create and train a CNN that could predict dog breeds from images of dogs. The image dataset used to train, validate, and test my CNN consisted of 8351 different dog images, with 133 different dog breeds given as labels. This data was provided by Udacity. The images were also passed through Google's InceptionV3 model before being passed into my CNN's layers.

Data Exploration & Visualization

The train/validation/test data used to refine my CNN consisted of 224 x 224 pixel jpg images of dogs (here's what some of them look like)

file

file

The images were then transformed by keras from 224X224 pixels into 4-D tensors, where the three color channels (RGB) are represented (each tensor was sized (1,224,224,3). The quantity of our input data and the train/validation/test splits are shown below: The target dog label count is also given.

total dog categories: 133


total dog images: 8351 
training dog images: 6680 
validation dog images: 835 
test dog images: 836 

An important exploratory analysis of the training data should include analyzing the distribution of labels for our training data. For example, if all of our train/validation images were of one dog breed, then our model wouldn't perform well on images of different dog breeds.

Here is the distribution of labels of the 6680 training and 835 validation images. We can see that most of the label counts for each dataset are close to the median, with very few outliers (the interquartile ranges are small compared to the mean:

file

file

Metrics

Accuracy was used as the final metric to gauge model performance because the sufficient representation of various dog breeds in the validation and train sets. Below are are other training data metrics found during training.

CNN Architecture

file

Train on 6680 samples, validate on 835 samples
Epoch 1/20
6560/6680 [============================>.] - ETA: 0s - loss: 2.9215 - acc: 0.4096Epoch 00001: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 506us/step - loss: 2.9058 - acc: 0.4115 - val_loss: 0.8396 - val_acc: 0.7521
Epoch 2/20
6600/6680 [============================>.] - ETA: 0s - loss: 1.5602 - acc: 0.6258Epoch 00002: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 455us/step - loss: 1.5630 - acc: 0.6254 - val_loss: 0.7016 - val_acc: 0.7940
Epoch 3/20
6620/6680 [============================>.] - ETA: 0s - loss: 1.3627 - acc: 0.6725Epoch 00003: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 456us/step - loss: 1.3683 - acc: 0.6716 - val_loss: 0.7009 - val_acc: 0.8132
Epoch 4/20
6640/6680 [============================>.] - ETA: 0s - loss: 1.3000 - acc: 0.6962Epoch 00004: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 455us/step - loss: 1.3050 - acc: 0.6963 - val_loss: 0.6377 - val_acc: 0.8060
Epoch 5/20
6580/6680 [============================>.] - ETA: 0s - loss: 1.2519 - acc: 0.7216Epoch 00005: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 455us/step - loss: 1.2463 - acc: 0.7225 - val_loss: 0.6217 - val_acc: 0.8311
.
.
.
.
.
.
Epoch 19/20
6580/6680 [============================>.] - ETA: 0s - loss: 1.1042 - acc: 0.7983Epoch 00019: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 456us/step - loss: 1.1002 - acc: 0.7985 - val_loss: 0.8792 - val_acc: 0.8371
Epoch 20/20
6580/6680 [============================>.] - ETA: 0s - loss: 1.0823 - acc: 0.8024Epoch 00020: saving model to saved_models/weights.best.inception.hdf5
6680/6680 [==============================] - 3s 455us/step - loss: 1.0801 - acc: 0.8030 - val_loss: 0.8824 - val_acc: 0.8599

Model Test Accuracy

Test accuracy: 82.6555%

Training Accuracy/Loss Curves

file

Installation and Run

The app uses the following non-standard packages: To see a list of all of the packages required to run the app, please look at the requirements.txt file in app_heroku.

Keras==2.4.3
dash==1.20.0
dash_core_components==1.16.0
opencv_python==4.5.1.48
tensorflow==2.4.1
dash_html_components==1.1.3
Pillow==8.2.0

File Descriptions

dog_app.ipynb : This file contains all of the work to build the model used in the app

dog_app.html : This is a copy of dog_app.ipynb

dog_app.pdf : This is a copy of dog_app.ipynb

app_heroku : This folder contains all of the files needed to deploy the app to heroku, or to run the app locally

    - `saved_models` : This folder contains all of the saved CNN model weights
    
    - `app.py` : This is the main app file
    
    - `dog_code.py` : This file reads in images in the app and applies the model to them

Run:

To view the app in Heroku: https://dogdash.herokuapp.com
To run the app locally, follow these steps:
  1. cd app_heroku
  2. pip install --user virtualenv
  3. virtualenv env
  4. source venv/bin/activate
  5. pip install -r requirements.txt
  6. python app.py

When using the app, keep the image size below 1MB for optimum performance!

Results

file

Licensing, Authors, Acknowledgements

These CNNs were used for transfer learning: InceptionV3, VGG16, and VGG19 were used. Acknowledgement goes to Udacity for the jupyter notebook template, their bottleneck data extraction code, and all of their lessons and help!

p4's People

Contributors

rangdipkinium avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.