本文介绍了如何清除 tf.flags?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行此代码两次:

If I run this code twice:

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的默认值.那么如何清除标志或允许重新定义标志的默认值呢?

I know that it's because of I redefine the default value of flag. So how can I clear flags or allow to redefine the flag's default value?

推荐答案

tf.flags.FLAGS.__delattr__() 

可以删除标志,所以定义一个函数来删除所有标志:

can delete flags, so define a function to delete all flags:

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)

这篇关于如何清除 tf.flags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:33