Giter Site home page Giter Site logo

sbrodehl / tf-retrain-model Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 1.0 65 KB

Retrain a Pretrained Model for New Categories with TensorFlow

License: MIT License

Python 100.00%
tensorflow tensorflow-tutorials tensorflow-models retrain inception-v3 pretrained-models

tf-retrain-model's Introduction

Retrain a Pretrained Model for New Categories

The full, detailed version of the tutorial(s) can be found on the TensorFlow website

Prerequisites

We will use the flower dataset to retrain the final layer of the inception model. The dataset can be downloaded here. The images are already split up into folders, corresponding to the different classes.

This is for the lazy.

wget http://download.tensorflow.org/example_images/flower_photos.tgz
tar -xf flower_photos.tgz

The pretrained model will be downloaded once at the beginning of the training.

Training

After preparing the data in the corresponding folders one can retrain the final layer of the model, also called transfer learning. See python3 retrain.py --help for more information on training parameters (etc.).

python3 retrain.py --image_dir flower_photos

This will train for a fixed amount of steps. The progress can be seen in tensorboad.

tensorboard --logdir=/tmp/retrain_logs

Visit the local tensorboard website to see pretty things like accuracy or cross entropy graphs.

Inference

Once the retraining of the final layer(s) is done one can use the model to do inference, that is, predict the class for unseen data. Inference is run on a single image (.png/.jpg/.bmp/.gif).

python3 label_image.py --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt --output_layer=final_result:0 --input_layer=Mul:0 --image=/FULL/PATH/TO/IMAGE.jpg

Using flower_photos/daisy/100080576_f52e8ee070_n.jpg the output will look like

daisy 0.938932
sunflowers 0.049032
dandelion 0.00581826

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.