To define command-line parameters using the Tf.app.flags interface __tensorflow

Source: Internet
Author: User
first, use the Tf.app.flags interface to define command line parametersAs we all know, deep learning has a lot of hyperparameter need to be tuned, tensorflow the bottom of the Python-gflags project, and then packaged into a tf.app.flags interface Using the Tf.app.flags interface can be very convenient to invoke the Define_string, Define_boolean, Define_integer, Define_float set different types of command-line arguments and their default values, In the actual project will generally defining command-line arguments in advance, as follows:
# coding:utf-8 # filename:flags.py Import tensorflow as TF # define a Global object to get the value of the parameter, use (eg:FLAGS.iteration) in the program to refer to the parameter flags = TF . App.flags.FLAGS # Defines command-line arguments, the first: parameter names, the second is: parameter defaults, and the third is: parameter description Tf.app.flags.DEFINE_integer ("Iteration", 200000, " Iterations to train [2e5] ") Tf.app.flags.DEFINE_integer (" Disp_freq ", 1000," Display "of the current results every Q iterations [1e3] ") Tf.app.flags.DEFINE_integer (" Save_freq ", Watts," Save the checkpoints every save_freq iterations [2e3 ] Tf.app.flags.DEFINE_float ("Learning_rate", 0.001, "learning rate of for Adam [0.001]") Tf.app.flags.DEFINE_integer ( "Train_batch_size", batch, "the size of the images [$]") Tf.app.flags.DEFINE_integer ("Val_batch_size", M, "the size of B Atch images []] Tf.app.flags.DEFINE_integer ("height", "M", "the" Height of "" [+] ") Tf.app.flags.DEFINE_integer (" width ", 160," the "width of the image to use.) [160] "Tf.app.flags.DEFINE_integer (" depth ", 3," Dimension of Image color. ") [3] ") tf.app.flags.DEFINE_string (" Data_dir "), "/path/to/data_sets/", "Directory of Datasets in the" form of Tfrecords. ") Tf.app.flags.DEFINE_string ("Checkpoint_dir", "/path/to/checkpoint_save_dir/", "Directory name to save" checkpoints [Checkpoint] ") tf.app.flags.DEFINE_string (" Model_name "," 40W_GRTR "," model name. [40w_grtr] "tf.app.flags.DEFINE_string (" gpu_id "," 0 "," Which GPU to be used. ") [0] ") Tf.app.flags.DEFINE_boolean (" Continue_train ", False," True for continue training.[ False] ") Tf.app.flags.DEFINE_boolean (" Per_image_standardization ", True," True for per_image_standardization.[ True] # defines the main function def main (argv=none): print (flags.iteration) print (flags.learning_rate) print (Flags.data_di   R) Print (Flags.continue_train) # executes main function if __name__ = = ' __main__ ': Tf.app.run ()
Ii. methods of implementing the procedure 1, the use of the default parameters in the programPython flags.py

2, the default parameters in the command line change program python flags.py--iteration=500000--learning_rate=0.01--data_dir= '/home/test/'-- Continue_train=true

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.