tensorflow-命令行参数

时间:2022-09-22 14:28:43
from tensorflow import app
from tensorflow.python.platform import flags


FLAGS = flags.FLAGS

# yapf: disable
flags.DEFINE_integer('task', 0,
                     'The Task ID. This value is used when training with '
                     'multiple workers to identify each worker.')


flags.DEFINE_integer('save_summaries_secs', 60,
                     'The frequency with which summaries are saved, in '
                     'seconds.')


flags.DEFINE_integer('max_number_of_steps', int(1e10),
                     'The maximum number of gradient steps.')

flags.DEFINE_string('checkpoint_inception', '',
                    'Checkpoint to recover inception weights from.')

flags.DEFINE_float('clip_gradient_norm', 2.0,
                   'If greater than 0 then the gradients would be clipped by '
                   'it.')

flags.DEFINE_bool('sync_replicas', False,
                  'If True will synchronize replicas during training.')


def main(_):
    print(FLAGS.task)
    print(FLAGS.checkpoint_inception)
    print(FLAGS.clip_gradient_norm)
    print(FLAGS.sync_replicas)


if __name__ == '__main__':
    app.run()

调用

 python flags.py --checkpoint_inception=logs