Retraining of InceptionV3 or MobileNet using TensorFlow and Docker.
Switch branches/tags
Nothing to show
Clone or download
KyleBanks Merge pull request #4 from mukulhase/master
Update Dockerfile with dockerhub tensorflow image
Latest commit 238ee39 Oct 29, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Resize bench example Dec 6, 2017
frame-extraction Initial Commit Dec 6, 2017
predictor Update Dockerfile Oct 24, 2018
train-classifier Update Dockerfile Oct 24, 2018
.gitignore Initial Commit Dec 6, 2017
LICENSE Initial Commit Dec 6, 2017
README.md added paragraph about directory structure Aug 29, 2018

README.md

tensorflow-docker-retrain

tensorflow-docker-retrain uses the TensorFlow framework to retrain an existing MobileNet (or InceptionV3) classifier via Docker without ever having to install TensorFlow.

You can provide your own training images from any source by creating the appropriate directory structure. This repository optionally provides the ability to split a video into individual frames that can be used to quickly gather a significant number of training images.

For a full tutorial on how this works and how to use it, click here.

Preparing Training Data from Videos

  1. Place your .mp4 video files in frame-extraction/videos/
  2. docker build -t frame-extraction frame-extraction/
  3. docker run -it -v $(pwd)/frame-extraction:/data frame-extraction
  4. Retrieve the split video frames from frame-extraction/frames/, and place in the appropriate directory structure.

Building input directory structure

You should have a folder containing class-named subfolders, each full of images for each label. The example folder would have a structure like this:

~/example/bench/bench.jpg
~/example/deadlift/deadlift.jpg
~/example/squat/anotherphoto77.jpg

The subfolder names are important, since they define what label is applied to each image, but the filenames themselves don't matter.

Training the Classifier

Before training you must build the generic train-classifier Docker image:

$ docker build -t train-classifier train-classifier/ 

Next invoke the train-classifier image by mounting the directory containing your training images as /input and an output directory as /output which will contain the trained model and labels text file after successful training.

$ docker run -it \
    -v $(pwd)/path/to/training-images:/input \
    -v $(pwd)/output:/output \
    train-classifier

Performing Predictions

Once you have a trained model, you can use it to perform predictions like so:

$ docker build -t predictor predictor/
$ docker run -it \
    -v $(pwd)/path/to/model/dir/:/model \
    -v $(pwd)/path/to/image:/input \
    predictor \
    image_name.jpg

Note: You need to mount two volumes here:

  1. /model is the path to your trained model and labels, the equivalent of /output/tf_files from the training step above.
  2. /input is the folder that contains your image to predict.

Finally, image_name.jpg can be substituted for the image you want to predict.

Examples

Using a model trained on approximately 750 images of the three powerlifts (Squat, Bench Press, and Deadlift), the output for two images that were not part of the training set (in fact none from this date or location were) looks like:

squat 0.999975
bench press 2.05499e-05
deadlift 4.10849e-06

bench press 0.930678
squat 0.0616271
deadlift 0.00769532

deadlift 0.928004
squat 0.0719689
bench press 2.72259e-05

Authors

License

MIT License

Copyright (c) 2017 Kyle Banks

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.