python - TensorFlow 中 tf.app.flags 的目的是什么?

标签 python tensorflow

我正在阅读 Tensorflow 中的一些示例代码,我发现以下代码

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
flags.DEFINE_integer('max_steps', 2000, 'Number of steps to run trainer.')
flags.DEFINE_integer('hidden1', 128, 'Number of units in hidden layer 1.')
flags.DEFINE_integer('hidden2', 32, 'Number of units in hidden layer 2.')
flags.DEFINE_integer('batch_size', 100, 'Batch size.  '
                 'Must divide evenly into the dataset sizes.')
flags.DEFINE_string('train_dir', 'data', 'Directory to put the training data.')
flags.DEFINE_boolean('fake_data', False, 'If true, uses fake data '
                 'for unit testing.')

tensorflow/tensorflow/g3doc/tutorials/mnist/fully_connected_feed.py

但我找不到任何关于 tf.app.flags 用法的文档。

我发现这个标志的实现是在 tensorflow/tensorflow/python/platform/default/_flags.py

显然,这个 tf.app.flags 以某种方式用于配置网络,那么为什么它不在 API 文档中呢?谁能解释这里发生了什么?

最佳答案

tf.app.flags 模块目前是 python-gflags 的薄包装,所以 documentation for that project是如何使用它的最佳资源 argparse ,它实现了 python-gflags 中的功能子集.

请注意,此模块目前是为了方便编写演示应用而打包的,从技术上讲,它不是公共(public) API 的一部分,因此将来可能会发生变化。

我们建议您使用 argparse 或您喜欢的任何库来实现自己的标志解析。

编辑: tf.app.flags 模块实际上并不是使用 python-gflags 实现的,但它使用了类似的 API。

关于python - TensorFlow 中 tf.app.flags 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33932901/

相关文章:

python - 如何将值从 html 传递到 python

tensorflow - 如何在 PyCharm 中将 tensorflow 文档设置为外部文档?

python - 如何在 Python 中将 Ragged Tensor 转换为 Tensor?

tensorflow - 了解 ResourceExhaustedError : OOM when allocating tensor with shape

python - 在 MATLAB 中检查梯度而不解决优化问题

Python 使用 cProfile 优化 cose

python - 使用具有多个输入因子的 sklearn 决策树进行回归会产生错误

python - LightGBMError : Do not support special JSON characters in feature name - The same code is working in jupyter but doesn't work in Spyder

python - 一定范围内的自定义准确度指标,用于回归

python - 如何在 Tensorflow 中结合 feature_columns、model_to_estimator 和数据集 API