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為默認值

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM