Tensorflow tf.app.run 的工作方式

To run a tensorflow app, you define the input, lost fn, model and EvaluationMonitor in a main function in your module like this.

执行 TensorFlow 的应用,需要定义输入、输入、网络模型和评估监控在主函数中,主函数要包含上述信息。

Like this,举例如下:

import tensorflow as tf
def main(unused_argv):
  hparams = ...
  model_fn = ...
  estimator = ...
  input_fn_train = ...
  input_fn_eval = ...
  eval_metrics = ...
  eval_monitor = ...
  # Start to train

if __name__ == "__main__":

Note, the last line, you need to fire tf.app.run. All the job are done in main. How does the main function is invoked?

注意,在上面最后一行,要调用 tf.app.run,那么这行的作用是什么?

tf.app.run lays out the thing

It’s just a very quick wrapper that handles flag parsing and then dispatches to your own main.

这个函数用来处理输入 flags,分发命令,启动执行任务。


Explanation code snippets

Chatopera博客 聊天机器人 机器学习 智能客服
已标记关键词 清除标记