dexter2406
dexter2406

Reputation: 461

Why absl flags returns True even when I assign False?

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)

Upvotes: 1

Views: 2318

Answers (3)

ttt
ttt

Reputation: 876

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

Upvotes: 2

Mandar
Mandar

Reputation: 498

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.

Upvotes: 0

dexter2406
dexter2406

Reputation: 461

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

Upvotes: 6

Related Questions