def run(main=None, argv=None):
"""Runs the program with an optional 'main' function and 'argv' list."""
f = flags.FLAGS
# Extract the args from the optional `argv` list.
args = argv[1:] if argv else None
# Parse the known flags from that list, or from the command
# line otherwise.
# pylint: disable=protected-access
flags_passthrough = f._parse_flags(args=args)
# pylint: enable=protected-access
main = main or sys.modules['__main__'].main
# Call the main function, passing through any arguments
# to the final program.
sys.exit(main(sys.argv[:1] + flags_passthrough))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
flags_passthrough=f._parse_flags(args=args)这里的_parse_flags就是我们tf.app.flags源码中用来解析命令行参数的函数。所以这一行就是解析参数的功能;
下面两行代码也就是 tf.app.run 的核心意思:执行程序中 main 函数,并解析命令行参数!
---------------------
作者:Never-Giveup
来源:CSDN
原文:https://blog.csdn.net/qq_36653505/article/details/81124533
版权声明:本文为博主原创文章,转载请附上博文链接!