TensorFlow Learning (i) defining command-line arguments using flags

Source: Internet
Author: User
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__ ': #避免出现import的时候调用main ()
    tf.app.run ()  #执行main函数

You can start the main () function python3 the Test.py–str_name liu–int_name 10来 on the command line.
In Pycharm, you can enter –str_name liu–int_name 10来 input parameters by Run->edit configurations and then in the script parameters.

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.