tensorflow tf.app.flags 元素被重复定义及delattr报错

tensorflow tf.app.flags 元素被重复定义及delattr报错


# 自定义命令行参数
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('f','','kernel')

result:(报错)
The flag ‘f’ is defined twice. First from /home/huanghanchi/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py, Second from /home/huanghanchi/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py. Description from first occurrence: kernel

solu

在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)

result:(报错)
AttributeError: delattr

solu

for循环中FLAGS.delattr(keys)改为FLAGS.__delattr__(keys)

你可能感兴趣的:(tensorflow tf.app.flags 元素被重复定义及delattr报错)