the usage or API of tf.app.flags

女生的网名这么多〃 提交于 2020-01-04 07:03:58

问题


When reading the cifar10 example, I can see the following code segment, which is said to follow the google commandline standard. But in specific, what does this code segment do? I did not find the API document to cover something like tf.app.flags.DEFINE_string

FLAGS = tf.app.flags.FLAGS

tf.app.flags.DEFINE_string('train_dir', '/tmp/cifar10_train',
                       """Directory where to write event logs """
                       """and checkpoint.""")
tf.app.flags.DEFINE_integer('max_steps', 1000000,
                        """Number of batches to run.""")
tf.app.flags.DEFINE_boolean('log_device_placement', False,
                        """Whether to log device placement.""")

回答1:


My experience with TensorFlow is that looking at the source code is often more useful than Ctrl+F in the API doc. I keep PyCharm open with the TensorFlow project, and can easily search for either example of how to do something (e.g., custom reader).

In this particular case, you want to look at what's going on in tensorflow/python/platform/flags.py. It's really just a thin wrapper around argparse.ArgumentParser(). In particular, all of the DEFINE_* end up adding arguments to a _global_parser, for example, through this helper function:

def _define_helper(flag_name, default_value, docstring, flagtype):
    """Registers 'flag_name' with 'default_value' and 'docstring'."""
    _global_parser.add_argument("--" + flag_name,
                                default=default_value,
                                help=docstring,
                                type=flagtype)

So their flags API is mostly the same as what you find for ArgumentParser.



来源:https://stackoverflow.com/questions/38510339/the-usage-or-api-of-tf-app-flags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!