tensorflow learning - tf.app.flags.DEFINE_XXXX() Use flags to define command line parameters

Like the argv in the main function written in C/C++, the tf framework also encapsulates the tf.app.flags.DEFINE_XXXX() function for defining parameters, which is convenient for passing parameters in the command line form. A common function form is as follows:

  1. flags.DEFINE_float(parameter 1, parameter 2, parameter 3 )  
  2. flags.DEFINE_integer( parameter 1, parameter 2, parameter 3 )  
  3. flags.DEFINE_string( parameter 1, parameter 2, parameter 3
  4. flags.DEFINE_boolean( parameter 1, parameter 2, parameter 3

Parameter 1: the defined parameter name;

Parameter 2: parameter default value;

Parameter 3: description of the parameter;

For example, in a common py file of a deep learning network:

import tensorflow as tfimport numpy as np#The first is the parameter name, the second is the default value, and the third is the parameter description
tf.app.flags.DEFINE_integer('batch_size', 64,'batch size=?') #Define the batch size of the input training data, the default is 64;
tf.app.flags.DEFINE_float('learning_rate', 0.001,'learning rate') #Define the size of the learning rate, the default is 0.001;
tf.app.flags.DEFINE_boolean('train', FALSE,'train or test') #Define the value of Boolean type to determine whether the network is training or testing
tf.app.flags.DEFINE_string('check_points_dir', './model/','check_points dir') #Model save path
tf.app.flags.DEFINE_integer('epoch', 50,'train epoch size') #Defined epoch size, the default is 50
FLAGS = tf.app.flags.FLAGS
def main(XXXX):
    XXXX
if __name__ == '__main__':
    XXXX #Execute main
 
 

 
 

 
 
When calling parameters, they are generally used as follows;
FLAGS.ParameterName
FLAGS.batch_size

PS! Really complain about the current style of CSDN! ! ! ! Not as stable as the old version of the editor…………………………What the hell

Guess you like

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