Home >Backend Development >Python Tutorial >tensorflow uses flags to define command line parameters
This article mainly introduces how tensorflow uses flags to define command line parameters. Now I share it with you and give it as a reference. Let’s take a look together
tf defines tf.app.flags to support accepting command line parameters, which is equivalent to accepting argv.
import tensorflow as tf #第一个是参数名称,第二个参数是默认值,第三个是参数描述 tf.app.flags.DEFINE_string('str_name', 'def_v_1',"descrip1") tf.app.flags.DEFINE_integer('int_name', 10,"descript2") tf.app.flags.DEFINE_boolean('bool_name', False, "descript3") FLAGS = tf.app.flags.FLAGS #必须带参数,否则:'TypeError: main() takes no arguments (1 given)'; main的参数名随意定义,无要求 def main(_): print(FLAGS.str_name) print(FLAGS.int_name) print(FLAGS.bool_name) if __name__ == '__main__': tf.app.run() #执行main函数
Execution:
[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 99 --bool_name True
test_str
99
True
Related recommendations:
How to export TensorFlow’s model network to a single file
The above is the detailed content of tensorflow uses flags to define command line parameters. For more information, please follow other related articles on the PHP Chinese website!