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
estimator.fit
if __name__ == "__main__":
tf.app.run()
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,分发命令,启动执行任务。
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/app.py