tf.app.run

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
用主函数和命令行参数列表,来跑程序

展开阅读全文

没有更多推荐了,返回首页