tf.app.run in tensorflow

In many demos released by TensorFlow, there is such code, as follows, what is this for?

[python]  view plain copy  
  1. if __name__ == "__main__":  
  2.     tf.app.run()   

Let's take a look at the source code:

[python]  view plain copy  
  1. # tensorflow/tensorflow/python/platform/default/_app.py  
  2.   
  3. # Copyright 2015 Google Inc. All Rights Reserved.  
  4. #  
  5. # Licensed under the Apache License, Version 2.0 (the "License");  
  6. # you may not use this file except in compliance with the License.  
  7. # You may obtain a copy of the License at  
  8. #  
  9. #     http://www.apache.org/licenses/LICENSE-2.0  
  10. #  
  11. # Unless required by applicable law or agreed to in writing, software  
  12. # distributed under the License is distributed on an "AS IS" BASIS,  
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  14. # See the License for the specific language governing permissions and  
  15. # limitations under the License.  
  16. # ==============================================================================  
  17.   
  18. """Generic entry point script."""  
  19. from __future__ import absolute_import  
  20. from __future__ import division  
  21. from __future__ import print_function  
  22.   
  23. import sys  
  24.   
  25. from tensorflow.python.platform import flags  
  26.   
  27.   
  28. def run(main=None):  
  29.   f = flags.FLAGS  
  30.   f._parse_flags()  
  31.   main = main or sys.modules['__main__'].main  
  32.   sys.exit(main(sys.argv))  

Process flag parsing, and then execute the main function, so what does flag parsing mean? Something like this:

[python]  view plain copy  
  1. tf.app.flags.DEFINE_boolean("self_test"False"True if running a self test.")  
  2. tf.app.flags.DEFINE_boolean('use_fp16'False,  
  3.                             "Use half floats instead of full floats if True.")  
  4. FLAGS = tf.app.flags.FLAGS  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325722916&siteId=291194637