Tensorflow flags = tf.app.flags 的使用

Tensorflow flags = tf.app.flags 的使用


在执行main函数之前首先进行flags的解析,也就是说TensorFlow通过设置flags来传递tf.app.run()所需要的参数,我们可以直接在程序运行前初始化flags,也可以在运行程序的时候设置命令行参数来达到传参的目的。

tf.app.flags的使用

例如:

flags = tf.app.flags
flags.DEFINE_integer("epoch", 1000, "Epoch to train [25]")
flags.DEFINE_float("learning_rate", 0.0002, "Learning rate of for adam [0.0002]")
flags.DEFINE_float("beta1", 0.5, "Momentum term of adam [0.5]")
flags.DEFINE_integer("train_size", 256, "The size of train images [np.inf]")
flags.DEFINE_integer("batch_size", 64, "The size of batch images [64]")
flags.DEFINE_string("dataset", "mnist", "The name of dataset [celebA, mnist, lsun]")
flags.DEFINE_boolean("train", True, "True for training, False for testing [False]")
FLAGS = flags.FLAGS

在类的初始化时可以赋值给类中的成员,例如:

   dcgan = DCGAN(
       sess,
       input_width=FLAGS.input_width,
       input_height=FLAGS.input_height,
       output_width=FLAGS.output_width,
       output_height=FLAGS.output_height,
       batch_size=FLAGS.batch_size,
       sample_num=FLAGS.batch_size,
       y_dim=10,
       dataset_name=FLAGS.dataset,
       input_fname_pattern=FLAGS.input_fname_pattern,
       crop=FLAGS.crop,
       checkpoint_dir=FLAGS.checkpoint_dir,
       sample_dir=FLAGS.sample_dir)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值