tf.app.flags的用法或API [英] the usage or API of tf.app.flags

查看:133
本文介绍了tf.app.flags的用法或API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当阅读 cifar10示例,我可以看到以下代码段,据说该段遵循google命令行标准。但是具体来说,此代码段的作用是什么?我找不到API文档来涵盖 tf.app.flags.DEFINE_string

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.""")


推荐答案

TensorFlow的经验是,在以下情况下,查看源代码通常比Ctrl + F更有用。 API文档。我通过TensorFlow项目保持PyCharm的开放状态,并且可以轻松地搜索如何做某事的示例(例如,自定义阅读器)。

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).

在这种特殊情况下,您想要看看 tensorflow / python / platform / flags.py 。实际上,它只是argparse.ArgumentParser()的薄薄包装。特别是,所有DEFINE_ *最终都会通过以下辅助函数将参数添加到_global_parser中:

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)

因此,它们的标志API与您在 ArgumentParser

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

这篇关于tf.app.flags的用法或API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆