Tensorflow:tf.flags的用法

tf.flags是用来设置参数的,以便后面的程序用到,感觉跟变量的作用是一样的。

# coding: utf-8

import tensorflow as tf

# define flags
tf.flags.DEFINE_integer("age", 17, "age of user(default:20)")
tf.flags.DEFINE_boolean("drink_allow", False, "if can drink or not(default:False)")
tf.flags.DEFINE_float("weight", 55.55, "weight of user(default:55.55kg)")
tf.flags.DEFINE_string("name", "Lilei", "name of user(default:Lilei)")

FLAGS = tf.flags.FLAGS  #init flags
FLAGS._parse_flags()  # parse flags

# get flags
for attr,value in FLAGS.__flags.items():
    print("attr:%s\tvalue:%s" % (attr,str(value)))

attr:name value:Lilei
attr:weight value:55.55
attr:age value:17
attr:drink_allow value:False

FLAGS.name = 'zhangshan'
# get flags
for attr,value in FLAGS.__flags.items():
    print("attr:%s\tvalue:%s" % (attr,str(value)))

attr:name value:zhangshan
attr:drink_allow value:False
attr:age value:17
attr:weight value:55.55

你可能感兴趣的:(tensorflow)