【问题标题】:What's the purpose of "FLAGS" in tensorflow张量流中“FLAGS”的目的是什么
【发布时间】:2017-12-23 01:34:42
【问题描述】:

我正在研究 tensorflow 中的mnist example

我对模块 FLAGS 感到困惑

# Basic model parameters as external flags.
FLAGS = None

在“run_training”功能中:

def run_training():
"""Train MNIST for a number of steps."""
# Tell TensorFlow that the model will be built into the default Graph.
with tf.Graph().as_default():
# Input images and labels.
images, labels = inputs(train=True, batch_size=FLAGS.batch_size,
                        num_epochs=FLAGS.num_epochs)

这里使用“FLAGS.batch_size”和“FLAGS.num_epochs”的目的是什么?我可以把它换成一个像 128 这样的常数吗?

我在this site找到了类似的答案,但还是看不懂。

【问题讨论】:

  • 您没有包含将FLAGS 定义为重要内容的代码。此外,您能解释一下您从其他问题中不明白的地方吗?

标签: python tensorflow deep-learning mnist


【解决方案1】:

标志通常用于解析命令行参数和保存输入参数。您可以将它们替换为常数,但最好在标志的帮助下组织您的输入参数。

【讨论】:

    【解决方案2】:

    对于mnist full_connect_reader的例子,实际上他们根本没有使用tensorflow FLAGS。这里的FLAGS,只是作为一个“全局变量”,由源码页按钮中的“FLAGS, unparsed = parser.parse_known_args()”赋值,用于不同的函数。

    tf.app.flags.FLAGS的使用方式应该是:

    import tensorflow as tf
    
    FLAGS = tf.app.flags.FLAGS
    
    tf.app.flags.DEFINE_integer('max_steps', 100,
                                """Number of batches to run.""")
    tf.app.flags.DEFINE_integer('num_gpus', 1,
                                """How many GPUs to use.""")
    
    
    def main(argv=None):
        print(FLAGS.max_steps)
        print(FLAGS.num_gpus)
    
    if __name__ == '__main__':
      # the first param for argv is the program name
      tf.app.run(main=main, argv=['tensorflow_read_data', '--max_steps', '50', '--num_gpus', '20'])
    

    【讨论】:

      猜你喜欢
      • 2016-10-20
      • 2018-11-10
      • 2019-03-27
      • 2017-09-03
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2020-03-18
      相关资源
      最近更新 更多