TensorFlow Learning (iii) defining command line parameters using flags __tensorflow

Source: Internet
Author: User

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

Import TensorFlow as TF

#第一个是参数名称, the second parameter is the default value, and 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

#必须带参数, otherwise: ' Typeerror:main () takes no arguments (1 given) ' ;   Main parameter name 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
False
[root@alihpc-g41-211 test]# python tt.py--str_name test_str--int_name--bool_name true
test_str%
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.