This article mainly introduces the method that TensorFlow uses the flags to define the command line parameters, and now share to everyone, also to make a reference. Come and see it together.
TF defines tf.app.flags, which is used to support accepting command-line pass parameters, equivalent to accepting argv.
Import TensorFlow as tf# the first is the parameter name, the second parameter is the default value, the third is the parameter description tf.app.flags.DEFINE_string (' Str_name ', ' def_v_1 ', ' descrip1 ') Tf.app.flags.DEFINE_integer (' Int_name ', ten, "Descript2") Tf.app.flags.DEFINE_boolean (' Bool_name ', False, "DESCRIPT3 ") FLAGS = tf.app.flags.flags# must take parameters, otherwise: ' Typeerror:main () takes no arguments (1 given) '; The parameter name of main is arbitrarily defined, no requirement def main (_): print (flags.str_name) print (flags.int_name) print (flags.bool_name) if __ name__ = = ' __main__ ': tf.app.run () #执行main函数
Perform:
[root@alihpc-g41-211 test]# python tt.py
Def_v_1
10
False
[root@alihpc-g41-211 test]# python tt.py--str_name test_str--int_name True
Test_str
99
True