kabkabm / defensegan

Defense-GAN: Protecting Classifiers Against Adversarial Attacks Using Generative Models (published in ICLR2018)
Apache License 2.0
229 stars 62 forks source link

absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'cfg'. Did you mean: cfg_path ? #20

Open 1993cathyzhao1993 opened 3 years ago

1993cathyzhao1993 commented 3 years ago

I follow ur instrumentation,but when I wanna train. absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'cfg'. Did you mean: cfg_path ?

This problem troubled me. How to solve this problem.hope to get ur answer. thanks

Zhuosd commented 2 years ago

I know how to deal with this problem!

My code is shown here:

flags = tf.compat.v1.app.flags

if not os.path.exists(cfg_path):
    raise RuntimeError(
        "[!] Configuration path {} does not exist.".format(cfg_path))
if os.path.isdir(cfg_path):
    cfg_path = os.path.join(cfg_path, 'cfg.yml')
    with open(cfg_path, 'r') as f:
        cfg = yaml.safe_load(f)
else:
    with open(cfg_path, 'r') as f:
        loaded_cfg = yaml.safe_load(f)
    base_dir = os.path.dirname(cfg_path)
    with open(os.path.join(base_dir, 'default.yml'), 'r') as f:
        cfg = yaml.safe_load(f)

    cfg.update(loaded_cfg)

with open(os.path.join('experiments/cfgs', 'key_doc.yml')) as f:
    docs = yaml.safe_load(f)

flags.DEFINE_string('cfg_path', cfg_path, 'config path.')