Coder Social home page Coder Social logo

transferlearncodenvy's Introduction

Transfer Learning Codenvy

Retraining one of Google's CNN image classification models to new categories using Transfer Learning. This can be an much faster (in a few minutes) than training from scratch (Inception V3 took Google, 2 weeks).

Install

sudo pip install --ignore-installed --upgrade https://github.com/lakshayg/tensorflow-build/releases/download/tf1.9.0-ubuntu16.04-py27-py35/tensorflow-1.9.0-cp35-cp35m-linux_x86_64.whl
sudo pip install tensorflow-hub

Tensorflow Builds

Create Codenvy project

mkdir retrain
cd retrain

Download Flowers

curl -LO http://download.tensorflow.org/example_images/flower_photos.tgz
tar xzf flower_photos.tgz

Download Retrain

curl -LO https://github.com/tensorflow/hub/raw/master/examples/image_retraining/retrain.py

Speedup Training

reduce the number of images by ~70% : 3681 -> 1668

ls flower_photos/* | wc -l
rm flower_photos/*/[3-9]*
rm flower_photos/daisy/ flower_photos/dandelion/ flower_photos/tulips/ -r
ls flower_photos/* | wc -l

also only use 2 flowers e.g. roses and sunflowers : 1668 -> 591

Retrain

python3 retrain.py --image_dir ./flower_photos --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/2 --how_many_training_steps 500

2m29s : Codenvy - Python 3 - 591 images - 500 Steps - mobilenet_v2_100_224 - Test 98.0%

Download Label Image

curl -LO https://github.com/tensorflow/tensorflow/raw/master/tensorflow/examples/label_image/label_image.py

Download Test Image

wget https://5.imimg.com/data5/AA/KK/MY-6677193/red-rose-500x500.jpg

Use the Retrained Model

python label_image.py --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt --input_layer=Placeholder --output_layer=final_result --input_height=224 --input_width=224 --image=red-rose-500x500.jpg | grep 'roses\|sunflowers'

Save Model

cp /tmp/output* ./

Training on Your Own Categories

download images, rename folder, zip, upload, unzip, mkdir, mv

Images

Batch Image downloader
Loads images on screen, in Google Images Scroll for more images.

Zip: in windows right click - Send to - Compressed (zipped) folder

Upload: in codenvy - Projects - Upload File

Unzip

unzip foldername.zip

Folders

mkdir images
mv foldername images

moves foldername into images folder

tmp

bottlenecks, graph & model in /tmp

Label Image with Inception & Imagenet

curl -LO https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz
tar -xvzf inception_v3_2016_08_28_frozen.pb.tar.gz
curl -LO https://raw.githubusercontent.com/EN10/SimpleInception/master/5918348-image.jpg
    
python label_image.py \
--graph=inception_v3_2016_08_28_frozen.pb --labels=imagenet_slim_labels.txt \
--image=5918348-image.jpg

transferlearncodenvy's People

Contributors

en10 avatar

Watchers

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