Search code examples
tensorflowcommand-line-argumentsgflags

What is the idiom for passing command line arguments to TensorFlow?


Previous versions of TensorFlow used tf.app.flags for command like flags:

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_string('data_dir', '/tmp/data/', 'Directory for storing data')

but recent versions now have just

import argparse
#...
FLAGS = None

wherever such code once appeared, importing argparse but not using it anywhere (that I can find).

The previous heavy use of tf.app.flags seemed like an endorsement of the gflags architecture as a kind of idiom for TensorFlow projects. Is it's removal an indication that another approach is now idiomatic and should be used in its place? If so, what approach, and is there a simple suggested migration path?


Solution

  • According to a commit 8018346 of TF, the maintainer of TF, vrv, replied:

    Yup! tf.flags is something that is used within Google but has a bunch of problems, we suggest using argparse when possible.

    As for the migration, you can checkout the same commit which did exactly the task.