tf.app.run()是做什么的?
if __name__ == "__main__":
tf.app.run()
可以看一下/usr/local/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py的源码
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))
_allowed_symbols = [
'run',
# Allowed submodule.
'flags',
]
remove_undocumented(__name__, _allowed_symbols)
其实就是处理flag解析,然后执行main函数
Runs the program with an optional ‘main’ function and ‘argv’ list
用主函数和命令行参数列表,来跑程序
本文详细解释了TensorFlow中tf.app.run()的功能及其工作原理。该函数主要用于解析命令行参数并执行主函数,通过调用此函数启动程序,简化了程序入口的编写。
5351

被折叠的 条评论
为什么被折叠?



