tf.flags

original

tf defines tf.app.flags to support accepting command line parameters, which is equivalent to accepting argv.

#The first is the parameter name, the second is the default value, and the third is the parameter description

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

#Must have parameters, otherwise: 'TypeError: main() takes no arguments (1 given)'; the parameter names of main are freely defined, no requirements

def main(_):

print(FLAGS.str_name)

print(FLAGS.int_name)

print(FLAGS.bool_name)

if __name__ == '__main__':

tf.app.run() #Execute the main function

implement:

python tt.py

def_v_1 10 False

python tt.py --str_name test_str --int_name 99 --bool_name True

test_str 99True

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325991094&siteId=291194637