tensorflow中tf.flags的基本用法

直接上例子代码:

# coding=utf-8
import tensorflow as tf
flags = tf.flags#flags是一个文件:flags.py,用于处理命令行参数的解析工作
FLAGS = flags.FLAGS#FLAGS是一个对象,保存了解析后的命令行参数
#第一个是参数名称,第二个参数是默认值,第三个是参数描述
flags.DEFINE_string("input_file", None, "The input file dir.")
flags.DEFINE_string("output_file", None, "The output file dir.")
flags.DEFINE_integer("batch_size", 256, "The size of a mini-batch.")

def main(_):
    print("The input file: " + FLAGS.input_file)#用"."获取参数
    print("The output file: " + FLAGS.output_file)
    print("The batch size: " + str(FLAGS.batch_size))

if __name__ == "__main__":
    flags.mark_flag_as_required("input_file")#表示必须指定的参数
    flags.mark_flag_as_required("output_file")
    tf.app.run()#先处理flag解析,然后执行main函数

运行输出

运行:$python test.py --input_file test.in --output_file test.out
输出:
	The input file: test.in
	The output file: test.out
	The batch size: 256
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值