Home > Mobile >  Flags deprecated in Tensorflow 2.0, what is the best alternative? [closed]
Flags deprecated in Tensorflow 2.0, what is the best alternative? [closed]

Time:09-24

I am working on a piece of code to preprocess image labels and turn them into tfrecords in an object detection project.

An old piece of code which I am using as a reference leveraged tf.app.flags and also tf.app.run from Tensorflow 1 to access arguments from the command line and start the script.

I'm looking to do things as properly as possible, so I feel like using tf.compat.v1.flags doesn't make a lot of sense 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()? what's the cleanest way to proceed.

CodePudding user response:

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)
  • Related