What's the purpose of tf.app.flags in TensorFlow?

前端 未结 5 1626

I am reading some example codes in Tensorflow, I found following code

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_float(\'learning_rate\', 0.01, \         


        
5条回答
  •  青春惊慌失措
    2020-12-04 07:14

    The tf.app.flags module is a functionality provided by Tensorflow to implement command line flags for your Tensorflow program. As an example, the code you came across would do the following:

    flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
    

    The first parameter defines the name of the flag while the second defines the default value in case the flag is not specified while executing the file.

    So if you run the following:

    $ python fully_connected_feed.py --learning_rate 1.00
    

    then the learning rate is set to 1.00 and will remain 0.01 if the flag is not specified.

    As mentioned in this article, the docs are probably not present because this might be something that Google requires internally for its developers to use.

    Also, as mentioned in the post, there are several advantages of using Tensorflow flags over flag functionality provided by other Python packages such as argparse especially when dealing with Tensorflow models, the most important being that you can supply Tensorflow specific information to the code such as information about which GPU to use.

提交回复
热议问题