diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2016-08-11 11:36:51 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-08-11 12:47:24 -0700 |
commit | f7c9fb5a9794d5bdc1efc58464832e6d955c83bc (patch) | |
tree | 68754828b23c186ebea42237523dbca2a10c6ada /tensorflow/examples/image_retraining | |
parent | 1a4751fe824352499352bbd400379fbc87a53a80 (diff) |
For static shape computations, use common_shapes.broadcast_shape..
Change: 130019247
Diffstat (limited to 'tensorflow/examples/image_retraining')
-rw-r--r-- | tensorflow/examples/image_retraining/data/labels.txt | 3 | ||||
-rw-r--r-- | tensorflow/examples/image_retraining/label_image.py | 137 |
2 files changed, 0 insertions, 140 deletions
diff --git a/tensorflow/examples/image_retraining/data/labels.txt b/tensorflow/examples/image_retraining/data/labels.txt deleted file mode 100644 index bc1131ac45..0000000000 --- a/tensorflow/examples/image_retraining/data/labels.txt +++ /dev/null @@ -1,3 +0,0 @@ -Runner-up -Winner -Loser diff --git a/tensorflow/examples/image_retraining/label_image.py b/tensorflow/examples/image_retraining/label_image.py deleted file mode 100644 index c93cab2893..0000000000 --- a/tensorflow/examples/image_retraining/label_image.py +++ /dev/null @@ -1,137 +0,0 @@ - -# Copyright 2016 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - - -"""Simple image classification with Inception. - -Run image classification with your model. - -This script is usually used with retrain.py found in this same -directory. - -This program creates a graph from a saved GraphDef protocol buffer, -and runs inference on an input JPEG image. You are required -to pass in the graph file and the txt file. - -It outputs human readable strings of the top 5 predictions along with -their probabilities. - -Change the --image_file argument to any jpg image to compute a -classification of that image. - -Example usage: -python label_image.py --graph=retrained_graph.pb - --labels=retrained_labels.txt - --image=flower_photos/daisy/54377391_15648e8d18.jpg - -NOTE: To learn to use this file and retrain.py, please see: - -https://codelabs.developers.google.com/codelabs/tensorflow-for-poets -""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import tensorflow as tf - -FLAGS = tf.app.flags.FLAGS - -# Flag definitions. -tf.app.flags.DEFINE_string('image', 'NOT_SET', - """Absolute path to image file.""") -tf.app.flags.DEFINE_integer('num_top_predictions', 5, - """Display this many predictions.""") -tf.app.flags.DEFINE_string('graph', 'NOT_SET', - """Absolute path to graph file (.pb)""") -tf.app.flags.DEFINE_string('labels', 'NOT_SET', - """Absolute path to labels file (.txt)""") - -tf.app.flags.DEFINE_string('output_layer', 'final_result:0', - """Name of the result operation""") -tf.app.flags.DEFINE_string('input_layer', 'DecodeJpeg/contents:0', - """Name of the input operation""") - - -def load_image(filename): - """Read in the image_data to be classified.""" - return tf.gfile.FastGFile(filename, 'rb').read() - - -def load_labels(filename): - """Read in labels, one label per line.""" - return [line.rstrip() for line in tf.gfile.GFile(filename)] - - -def load_graph(filename): - """Unpersists graph from file as default graph.""" - with tf.gfile.FastGFile(filename, 'rb') as f: - graph_def = tf.GraphDef() - graph_def.ParseFromString(f.read()) - tf.import_graph_def(graph_def, name='') - - -def run_graph(image_data, labels, input_layer_name, output_layer_name): - with tf.Session() as sess: - # Feed the image_data as input to the graph. - # predictions will contain a two-dimensional array, where one - # dimension represents the input image count, and the other has - # predictions per class - predictions = sess.run(output_layer_name, - {input_layer_name: image_data}) - - # We're only ever passing one image in to be classified, so we - # just need the first line of the softmax_tensor. - predictions = predictions[0] - - # Sort to show labels in order of confidence - top_k = predictions.argsort()[-FLAGS.num_top_predictions:][::-1] - for node_id in top_k: - human_string = labels[node_id] - score = predictions[node_id] - print('%s (score = %.5f)' % (human_string, score)) - - return 0 - - -def main(_): - """Runs inference on an image. - - Returns: - Nothing - """ - - if not tf.gfile.Exists(FLAGS.image): - tf.logging.fatal('image file does not exist %s', FLAGS.image) - - if not tf.gfile.Exists(FLAGS.labels): - tf.logging.fatal('labels file does not exist %s', FLAGS.labels) - - if not tf.gfile.Exists(FLAGS.graph): - tf.logging.fatal('graph file does not exist %s', FLAGS.graph) - - # load image - image_data = load_image(FLAGS.image) - - # load labels - labels = load_labels(FLAGS.labels) - - # load graph, which is stored in the default session - load_graph(FLAGS.graph) - - run_graph(image_data, labels, FLAGS.input_layer, FLAGS.output_layer) - -if __name__ == '__main__': - tf.app.run() |