TensorFlow using flags to define command-line arguments

Source: Internet
Author: User
This article mainly introduces the method that TensorFlow uses the flags to define the command line parameters, and now share to everyone, also to make a reference. Come and see it together.

TF defines tf.app.flags, which is used to support accepting command-line pass parameters, equivalent to accepting argv.

Import TensorFlow as tf# the first is the parameter name, the second parameter is the default value, the third is the parameter description tf.app.flags.DEFINE_string (' Str_name ', ' def_v_1 ', ' descrip1 ') Tf.app.flags.DEFINE_integer (' Int_name ', ten, "Descript2") Tf.app.flags.DEFINE_boolean (' Bool_name ', False, "DESCRIPT3 ") FLAGS = tf.app.flags.flags# must take parameters, otherwise: ' Typeerror:main () takes no arguments (1 given) ';  The parameter name of main is arbitrarily defined, no requirement def main (_):   print (flags.str_name)  print (flags.int_name)  print (flags.bool_name) if __ name__ = = ' __main__ ':  tf.app.run () #执行main函数

Perform:

[root@alihpc-g41-211 test]# python tt.py
Def_v_1
10
False
[root@alihpc-g41-211 test]# python tt.py--str_name test_str--int_name True
Test_str
99
True

Related Article

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.