Why absl flags returns True even when I assign False?

1.7k views Asked by At

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)
3

There are 3 answers

1
dexter2406 On

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....

0
Mandar On

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.

0
TNg On

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