1

Here is the code. I tried to give this parameter 'False' value by using

python file.py --add_depth_loss False

but it still print "True".... Why is that?

from absl import flags, app

FLAGS = flags.FLAGS
flags.DEFINE_boolean('add_depth_loss', None, 'sss')
flags.mark_flag_as_required('add_depth_loss')

def main(_):
    print(FLAGS.add_depth_loss)

if __name__ == '__main__':
    app.run(main)
khelwood
  • 55,782
  • 14
  • 81
  • 108
dexter2406
  • 451
  • 4
  • 14
  • 2
    You are reading those values before you called `app.run`. I suspect you need to move those inside of your `main` function. – Tim Roberts May 08 '21 at 21:29

3 Answers3

6

After some research, I found that the bool or boolean flag is not used this way. It's actually a "set True" option. If you want to set False you need to do ---option=false instead of --option False like other types, otherwise it always return True.

Even if you set

flags.bool('option', None, 'xxx')
flags.mark_as_required('option')

and pass --option False, it also returns True.

Well, I'm speechless....

dexter2406
  • 451
  • 4
  • 14
0

Just adding more context from the documentation https://abseil.io/docs/python/guides/flags

DEFINE_bool or DEFINE_boolean: typically does not take an argument: pass --myflag to set FLAGS.myflag to True, or --nomyflag to set FLAGS.myflag to False. --myflag=true and --myflag=false are also supported, but not recommended.

Mandar
  • 498
  • 1
  • 4
  • 17
0

Use python file.py --noadd_depth_loss instead to set add_depth_loss to False.

TNg
  • 856
  • 1
  • 9
  • 15