diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2016-10-14 15:41:38 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-10-14 16:48:42 -0700 |
commit | 20c02ffe0e6b8af4902487f852e15daa16caa523 (patch) | |
tree | bd2b821e5021f714bf5db3a92bbb269ea715002d /tensorflow/examples/label_image | |
parent | 5c1821be018d4a626efd0a9cee7844aaa8c69366 (diff) |
Modify tensorflow command line flag parsing:
- Allow help text to be specified for each flag
- Add a flag "--help" to print the help text
- Rename ParseFlags to Flags::Parse(); new routine Flags::Usage() returns a
usage message.
- Change uses to new format
In some cases reorder with InitMain(), which should be called after flag parsing.
Change: 136212902
Diffstat (limited to 'tensorflow/examples/label_image')
-rw-r--r-- | tensorflow/examples/label_image/main.cc | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/tensorflow/examples/label_image/main.cc b/tensorflow/examples/label_image/main.cc index 7faf1cef61..3a927ca14b 100644 --- a/tensorflow/examples/label_image/main.cc +++ b/tensorflow/examples/label_image/main.cc @@ -32,6 +32,7 @@ limitations under the License. // The googlenet_graph.pb file included by default is created from Inception. #include <fstream> +#include <vector> #include "tensorflow/cc/ops/const_op.h" #include "tensorflow/cc/ops/image_ops.h" @@ -246,27 +247,32 @@ int main(int argc, char* argv[]) { string output_layer = "softmax"; bool self_test = false; string root_dir = ""; - const bool parse_result = tensorflow::ParseFlags( - &argc, argv, {Flag("image", &image), // - Flag("graph", &graph), // - Flag("labels", &labels), // - Flag("input_width", &input_width), // - Flag("input_height", &input_height), // - Flag("input_mean", &input_mean), // - Flag("input_std", &input_std), // - Flag("input_layer", &input_layer), // - Flag("output_layer", &output_layer), // - Flag("self_test", &self_test), // - Flag("root_dir", &root_dir)}); + std::vector<Flag> flag_list = { + Flag("image", &image, "image to be processed"), + Flag("graph", &graph, "graph to be executed"), + Flag("labels", &labels, "name of file containing labels"), + Flag("input_width", &input_width, "resize image to this width in pixels"), + Flag("input_height", &input_height, + "resize image to this height in pixels"), + Flag("input_mean", &input_mean, "scale pixel values to this mean"), + Flag("input_std", &input_std, "scale pixel values to this std deviation"), + Flag("input_layer", &input_layer, "name of input layer"), + Flag("output_layer", &output_layer, "name of output layer"), + Flag("self_test", &self_test, "run a self test"), + Flag("root_dir", &root_dir, + "interpret image and graph file names relative to this directory"), + }; + string usage = tensorflow::Flags::Usage(argv[0], flag_list); + const bool parse_result = tensorflow::Flags::Parse(&argc, argv, flag_list); if (!parse_result) { - LOG(ERROR) << "Error parsing command-line flags."; + LOG(ERROR) << usage; return -1; } // We need to call this to set up global state for TensorFlow. tensorflow::port::InitMain(argv[0], &argc, &argv); if (argc > 1) { - LOG(ERROR) << "Unknown argument " << argv[1]; + LOG(ERROR) << "Unknown argument " << argv[1] << "\n" << usage; return -1; } |