Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear tf.flags?

If I run this code twice:

tf.flags.DEFINE_integer("batch_size", "2", "batch size for training")

I will get this error:

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

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?

like image 414
0811张庆昊 Avatar asked Apr 19 '18 09:04

0811张庆昊


Video Answer


1 Answers

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)

Then run:

del_all_flags(tf.flags.FLAGS)
like image 80
0811张庆昊 Avatar answered Oct 04 '22 01:10

0811张庆昊