阅读 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.""")
最佳答案
我使用 TensorFlow 的经验是,查看源代码通常比 API 文档中的 Ctrl+F 更有用。我使 PyCharm 与 TensorFlow 项目保持打开状态,并且可以轻松搜索如何执行某些操作的示例(例如自定义阅读器)。
在这种特殊情况下,您想要查看 tensorflow/python/platform/flags.py 中发生了什么。它实际上只是 argparse.ArgumentParser() 的一个薄包装。特别是,所有 DEFINE_* 最终都会向 _global_parser 添加参数,例如通过以下辅助函数:
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 中找到的 API 基本相同。 .
关于python - tf.app.flags 的用法或 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38510339/