tensorflow models flags 初步使用

 

参考官方仓库:https://github.com/tensorflow/models/tree/master/official/utils/flags

测试Demo代码如下:

from absl import app as absl_app
from absl import flags

from official.utils.flags import core as flags_core

flags.DEFINE_string(name="my_flag_a", default="aaa", help="an example flag")
flags.DEFINE_string(name="my_flag_b", default="bbb", help="an other example flag")


def main(_):
    flags_obj = flags.FLAGS
    print(flags_obj)
    print(flags_obj.my_flag_a)
    print(flags_obj.my_flag_b)


if __name__ == "__main__":
    absl_app.run(main)

Terminal运行执行如下脚本:

python tensorflow_example/test_absl_flags.py --log_dir "./logs"  --my_flag_a "flag_aaa"

输出结果:

tensorflow_example/test_absl_flags.py:
  --my_flag_a: an example flag
    (default: 'aaa')
  --my_flag_b: an other example flag
    (default: 'bbb')

absl.app:
  -?,--[no]help: show this help
    (default: 'false')
  --[no]helpfull: show full help
    (default: 'false')
  -h,--[no]helpshort: show this help
    (default: 'false')
  ......

absl.logging:
  --[no]alsologtostderr: also log to stderr?
    (default: 'false')
  --log_dir: directory to write logfiles into
  ......

absl.flags:
  --flagfile: Insert flag definitions from the given file into the command line.
    (default: '')
  --undefok: comma-separated list of flag names that it is okay to specify on the command line even if the program does not define a flag with that name.  IMPORTANT: flags in this
    list that have arguments MUST use the --flag=value format.
    (default: '')
flag_aaa
bbb

其中最后两行,表示flags_obj.my_flag_a为设置后的值,flags_obj.my_flag_b为默认值

 

转载于:https://www.cnblogs.com/xbit/p/10065067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值