如果我运行此代码两次:
tf.flags.DEFINE_integer("batch_size", "2", "batch size for training")
我会收到此错误:
DuplicateFlagError: The flag 'batch_size' is defined twice. First from D:/Python/workspace/FCN_dataset/FCN.tensorflow-master/FCN.py, Second from D:/Python/workspace/FCN_dataset/FCN.tensorflow-master/FCN.py. Description from first occurrence: batch size for training
我知道这是因为我重新定义了flag的默认值。那么如何清除标志或允许重新定义标志的默认值呢?
答案 0 :(得分:10)
tf.flags.FLAGS.__delattr__()
可以删除标志,因此定义一个删除所有标志的函数:
def del_all_flags(FLAGS):
flags_dict = FLAGS._flags()
keys_list = [keys for keys in flags_dict]
for keys in keys_list:
FLAGS.__delattr__(keys)
然后运行:
del_all_flags(tf.flags.FLAGS)