JoshSucksAtCoding
JoshSucksAtCoding

Reputation: 23

Flags deprecated in Tensorflow 2.0, what is the best alternative?

tf.app.flags and tf.app.run from Tensorflow 1 were removed from Tensorflow 2. Is there a better alternative than using tf.compat.v1.flags given I am writing the script from scratch.

What's the best way to do this? Should I just stick with argparse and run main()?

Upvotes: 2

Views: 1977

Answers (1)

user1635327
user1635327

Reputation: 1641

Instead of tf.app.flags, it is recommended to use abseil-py. An example,

from absl import app
from absl import flags
from absl import logging

FLAGS = flags.FLAGS

flags.DEFINE_string('flag', None, 'Text')

def main(argv):
  logging.info('flag is %s.', FLAGS.flag)

if __name__ == '__main__':
  app.run(main)

Upvotes: 2

Related Questions