如何在Tensorflow中打印标志描述?

时间:2015-12-16 14:22:13

标签: python tensorflow

Google有许多使用标记的示例。它们都在定义中有描述。有没有办法可以将这些说明打印到终端?

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_boolean('test_mode', False, 'This is the description I want A.')
flags.DEFINE_boolean('cool_mode', True, 'This is the description I want B.')

2 个答案:

答案 0 :(得分:8)

TensorFlow中使用的flags模块是python-gflags module的包装器。要查看使用python-gflags在Python应用程序中使用的所有标志的列表,可以使用-h--help标志运行它。例如:

$ tensorboard -h
usage: tensorboard [-h] [--logdir LOGDIR] [--debug DEBUG] [--nodebug]
                   [--host HOST] [--port PORT]

optional arguments:
  -h, --help       show this help message and exit
  --logdir LOGDIR  logdir specifies where TensorBoard will look to find
                   TensorFlow event files that it can display. In the simplest
                   case, logdir is a directory containing tfevents files.
                   TensorBoard also supports comparing multiple TensorFlow
                   executions: to do this, you can use directory whose
                   subdirectories contain tfevents files, as in the following
                   example: foo/bar/logdir/
                   foo/bar/logdir/mnist_1/events.out.tfevents.1444088766
                   foo/bar/logdir/mnist_2/events.out.tfevents.1444090064 You
                   may also pass a comma seperated list of log directories,
                   and you can assign names to individual log directories by
                   putting a colon between the name and the path, as in
                   tensorboard
                   --logdir=name1:/path/to/logs/1,name2:/path/to/logs/2
  --debug DEBUG    Whether to run the app in debug mode. This increases log
                   verbosity to DEBUG.
  --nodebug
  --host HOST      What host to listen to. Defaults to allowing remote access,
                   set to 127.0.0.1 to serve only on localhost.
  --port PORT      What port to serve TensorBoard on.

答案 1 :(得分:2)

一种棘手的方式:

print(FLAGS.__dict__['__flags'])

您可以在文件tensorflow/python/platform/flags.py

中找到原因