TF defines tf.app.flags, which is used to support accepting command-line pass parameters, which is equivalent to accepting argv.
Import TensorFlow as TF
#第一个是参数名称, the second parameter is the default value, and 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
#必须带参数, otherwise: ' Typeerror:main () takes no arguments (1 given) ' ; Main parameter name 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
False
[root@alihpc-g41-211 test]# python tt.py--str_name test_str--int_name--bool_name true
test_str%
true