tf.app.flags的用法或API

2024-06-06 19:10:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在阅读cifar10 example时,我可以看到下面的代码段,据说它遵循google命令行标准。但具体来说,这个代码段是做什么的?我没有找到API文档来覆盖类似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.""")

Tags: tologappstringexampledevicetf代码段
1条回答
网友
1楼 · 发布于 2024-06-06 19:10:17

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

在这种特殊情况下,您需要查看tensorflow/python/platform/flags.py中发生了什么。它实际上只是argparse.ArgumentParser()的一个薄包装。特别是,所有DEFINE最后都会向全局解析器添加参数,例如,通过这个helper函数:

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中找到的相同。

相关问题 更多 >