GithubHelp home page GithubHelp logo

gtyagics / image-classifier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avn3r/image-classifier

0.0 2.0 0.0 171 KB

Image Classification based on Transfer Learning of Deep Learning Convolutional Neural Networks

Python 100.00%

image-classifier's Introduction

Image Classification: Fine-Tune CNN Model via Transfer Learning

Although model has been optimized for specific image classification task, this code can be used as a generic image classifier for any problem.

Requirements:

This project was built using Ubuntu 16.10, Ananconda, Keras, and Tensorflow. The code has been tested with both CPU (64GB RAM computer) and GPU (2x Nvidia GeForce GTX 1080). To clone one of the two enviorments provided follow the instructions below.

  1. Download Anaconda
  2. Download Dataset AND Models: only the dogs vs. cats data is provided, since the text_images data is not public.
  3. Clone Environment: (CPU): conda env create -f cpu-environment.yml
  4. Clone Environment: (GPU): conda env create -f gpu-environment.yml

Code:

The code contains two training model, and one classification output.

  1. fine_tune.py: used to train CNN to classify between dogs vs. cats.
  2. fine_tune_text_images: used to train CNN to classify between handwritten vs. typed.
  3. classify.py: used to classify new samples for either training model

Training: Dogs vs. Cats Example

Both the dogs_cats and text_images classifier have already been trained and their best models will be saved on the model directory after downloading them models download. If you do not wish to re-train the models feel free to skip this step and go straight into classifying new samples.

image-classifier$ source activate image-classifier-cpu
image-classifier$ python code/fine_tune.py <data_dir/> <model_dir/>

Example: python code/fine_tune.py data/dogs_cats/ model/dogs_cats/

  • Make sure to include the / at the end of every directory for the example to work.
  • Replace image-classifier-cpu with image-classifier-gpu if your using GPU

The training script will save the json model model.json, and model_weights.h5 file in the specified <model_dir/>

Classify: Dogs vs. Cats Example

For text_images dataset parameters are nb_test_samples=10, img_width=600, img_height=150 must be change according to your model and needs. Values provided are just default ones.

For dogs vs cats dataset just leave default values.

image-classifier$ source activate image-classifier-cpu
image-classifier$ python code/classify.py <model_dir/> <test_dir/> <results_dir/>

Example: python code/classify.py model/dogs_cats/ data/dogs_cats/test/ results/dogs_cats/

  • Make sure to include the / at the end of every directory for the example to work.
  • Replace image-classifier-cpu with image-classifier-gpu if your using GPU
  • <test_dir/> should contain a subfolder inside and NOT the data directly. Example: test_dir/test

The classify script will save a predictions.csv file in the specified <results_dir/>

Model:

This directory contains the best models already train for both classification tasks.

Results:

This directory contains the test results for both classification tasks.

Best Value:

  • Dog vs. Cats: 99.38% validation accuracy, .02 validation log loss
  • Handwritten vs Typed: 100% validation accuracy

Data:

This empty directory is created to store the dataset if desired. Download the dataset from the requirements section and place it inside this folder. Example: data/dogs_cats/..

Acknowledgement:

A significant portion of this script came from keras blog example: "Building powerful image classification models using very little data" My main contribution is to make it work with all keras pre-train applications models, and add a higher level of abstraction.

image-classifier's People

Watchers

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