Coder Social home page Coder Social logo

wwoo / tf_box_classify Goto Github PK

View Code? Open in Web Editor NEW
11.0 6.0 9.0 37.34 MB

A simple TensorFlow example for training CNN models using input queues and labelled JPEGs

Python 14.03% HTML 1.54% C++ 3.69% Protocol Buffer 0.20% Jupyter Notebook 80.55%

tf_box_classify's Introduction

Classifying boxes using TensorFlow

This is a simple example of how to build a convolutional neural network (CNN) with TensorFlow. It extends existing MNIST convnet examples with TensorFlow input queues for reading training and validation data in common image formats like JPEG. You should be able to easily change the sample code and text files to use your own training data.

Link to YouTube Video

The sample training data and code classifies images of a toy box into four states:

  1. Upright (box is upright)
  2. Tilted (box is tilted on its side)
  3. Open (box is upright and open)
  4. Spilled (box is tilted on it's side, open with contents spilled)

115 images for each class is used to train the model.

tf_convnet_test.ipynb is a Jupyter notebook which runs through the training example.

The main code samples are:

tf_convnet_test.py reads the training and validation data from train.txt and valid.txt, then builds and executes the TensorFlow graph. Run it with no arguments:

python tf_convnet_test.py

tf_convnet_export.py does all the above, and also exports the trained model. You'll need to install or build TensorFlow Serving to run this. Run it with no arguments:

python tf_convnet_export.py

tf_convnet_inference.cc serves the trained TensorFlow Serving. You'll need to install or build TensorFlow Serving to compile it. The code is slightly modified from the MNIST inference sample included with the TensorFlow SDK, most notably changing the shape of the input data and number of output classes. Run it by specifying the port and location of the exported model.

tf_convnet_inference --port=9000 location/to/model/dir/

web_server.py is a simple Flask application that takes images using a webcam and sends them to the inference server for classification. It has only been "tested" on Chrome. Run it with no arguments:

python web_server.py

I don't have a pattern for the box, but if you want to build your own, it is

  • 50x50x50mm
  • made of balsa wood
  • has white electrical tape on the sides to hold it together
  • has an articulating "lid"
  • filled coloured pom poms on the inside
  • marked on four sides with a "this side up" decal

tf_box_classify's People

Contributors

wintwoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tf_box_classify's Issues

How to run the script ?

I run python tf_convnet_test.py correctly

but I dont know how should I run tf_convnet_inference.cc or python tf_convnet_export.py I get many errors

grasp001@grasp001:~/tf_box_classify$ python tf_convnet_export.py 
Traceback (most recent call last):
  File "tf_convnet_export.py", line 20, in <module>
    from tensorflow_serving.session_bundle import exporter
ImportError: No module named tensorflow_serving.session_bundle

Value error of images

When i run below script then get following error.

$ python2 tf_convnet_test.py

get_image_label_list: read 460 items
Traceback (most recent call last):
File "tf_convnet_test.py", line 286, in
tf.app.run()
File "/home/test/Tensorflow/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "tf_convnet_test.py", line 154, in main
batch_size=TRAIN_BATCH_SIZE, num_epochs=TRAIN_EPOCHS)
File "tf_convnet_test.py", line 61, in inputs
image, label = read_image_from_disk(input_queue)
File "tf_convnet_test.py", line 53, in read_image_from_disk
rgb_image = tf.image.resize_images(rgb_image, IMAGE_SIZE, IMAGE_SIZE)
File "/home/test/Tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/image_ops_impl.py", line 659, in resize_images
raise ValueError(''size' must be a 1-D Tensor of 2 elements: '
ValueError: 'size' must be a 1-D Tensor of 2 elements: new_height, new_width

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.