Warnings for TensorFlow User
Warnings for TensorFlow User¶
This is (to be) a collection of warnings for TF users.
TF Flag¶
Flags is a useful replacement for the argparse and other libraries. It has been used extensively in TF codes. However, it claims to be "Import router for absl.flags. See https://github.com/abseil/abseil-py." from the version 1.13 documentation. But it is not the flag in abseil.
The major problem I encountered is that if the argument is mis-spelled, there is NO warning in TF. And it is different from the behaviour in abseil. So try to use the abseil version for a peaceful mind.
See the example below:
In [0]:
with open("test_absl.py","w") as f:
f.write("""from absl import app
FLAGS = app.flags.FLAGS
app.flags.DEFINE_integer('a', 0, 'var')
def main(unused):
print("value a is %d"%FLAGS.a)
if __name__ == "__main__":
app.run(main)""")
In [2]:
# default run
!python test_absl.py
# change a to 2
!python test_absl.py --a 2
# wrong argument
!python test_absl.py --b 1
In [0]:
with open("test_tf.py","w") as f:
f.write("""from tensorflow.compat.v1 import app # before v1.13 - from tensorflow import app
FLAGS = app.flags.FLAGS
app.flags.DEFINE_integer('a', 0, 'var')
def main(unused):
print("value a is %d"%FLAGS.a)
if __name__ == "__main__":
app.run(main)
""")
In [4]:
# default run
!python test_absl.py
# change a to 2
!python test_absl.py --a 2
# wrong argument
!python test_absl.py --b 1
Comments