if __name__ == "__main__": tf.app.run()

if __name__ == "__main__": means current file is executed under a shell instead of imported as a module.
the job of tf.app.run() is to first set the global flags for later usage like

    from tensorflow.python.platform import flags

    f = flags.FLAGS

and then run your custom main function with a set of arguments.

原文地址:https://www.cnblogs.com/qingliu411/p/9175896.html