当前位置:网站首页>Brief introduction of TF flags
Brief introduction of TF flags
2020-11-06 01:22:00 【Elementary school students in IT field】
1、TF flags An introduction to the
1、flags Can help us through the command line to dynamically change the parameters in the code .Tensorflow Use flags How to define command line arguments .ML There's a lot of need for tuning The super parameter of , So this method , To meet the need for a flexible way to adjust some parameters of the code
(1)、 such as , In this py In file , First, some parameters are defined , Then save the parameters to variables FLAGS in , Equivalent to assignment , When these parameters are called later, they are used directly FLAGS Parameters can be
(2)、 There are three basic parameter types flags.DEFINE_integer、flags.DEFINE_float、flags.DEFINE_boolean.
(3)、 The first is the parameter name , The second parameter is the default value , The third is parameter description
2、 Using process
# First step , call flags = tf.app.flags, Define parameter name , And the initial value can be given 、 Parameter description
# The second step ,flags Parameters are assigned directly
# The third step , function tf.app.run()
FLAGS = tf.flags.FLAGS
tf.flags.DEFINE_string('name', 'default', 'name of the model')
tf.flags.DEFINE_integer('num_seqs', 100, 'number of seqs in one batch')
tf.flags.DEFINE_integer('num_steps', 100, 'length of one seq')
tf.flags.DEFINE_integer('lstm_size', 128, 'size of hidden state of lstm')
tf.flags.DEFINE_integer('num_layers', 2, 'number of lstm layers')
tf.flags.DEFINE_boolean('use_embedding', False, 'whether to use embedding')
tf.flags.DEFINE_integer('embedding_size', 128, 'size of embedding')
tf.flags.DEFINE_float('learning_rate', 0.001, 'learning_rate')
tf.flags.DEFINE_float('train_keep_prob', 0.5, 'dropout rate during training')
tf.flags.DEFINE_string('input_file', '', 'utf8 encoded text file')
tf.flags.DEFINE_integer('max_steps', 100000, 'max steps to train')
tf.flags.DEFINE_integer('save_every_n', 1000, 'save the model every n steps')
tf.flags.DEFINE_integer('log_every_n', 10, 'log to the screen every n steps')
tf.flags.DEFINE_integer('max_vocab', 3500, 'max char number')
Examples are as follows :
import tensorflow as tf
# Take part of the above code for experiment
tf.flags.DEFINE_integer('num_seqs', 100, 'number of seqs in one batch')
tf.flags.DEFINE_integer('num_steps', 100, 'length of one seq')
tf.flags.DEFINE_integer('lstm_size', 128, 'size of hidden state of lstm')
# adopt print() Determine the function of the following
FLAGS = tf.flags.FLAGS #FLAGS Save data for command line arguments
FLAGS._parse_flags() # Parse it into a dictionary and store it in FLAGS.__flags in
print(FLAGS.__flags)
print(FLAGS.num_seqs)
print("\nParameters:")
for attr, value in sorted(FLAGS.__flags.items()):
print("{}={}".format(attr.upper(), value))
print("")
You can refer to : Related solutions

版权声明
本文为[Elementary school students in IT field]所创,转载请带上原文链接,感谢
边栏推荐
- Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
- Microservices: how to solve the problem of link tracing
- 比特币一度突破14000美元,即将面临美国大选考验
- What problems can clean architecture solve? - jbogard
- ES6 essence:
- Using Es5 to realize the class of ES6
- Process analysis of Python authentication mechanism based on JWT
- 华为云“四个可靠”的方法论
- Skywalking series blog 1 - install stand-alone skywalking
- Thoughts on interview of Ali CCO project team
猜你喜欢
合约交易系统开发|智能合约交易平台搭建
Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
Don't go! Here is a note: picture and text to explain AQS, let's have a look at the source code of AQS (long text)
做外包真的很难,身为外包的我也无奈叹息。
关于Kubernetes 与 OAM 构建统一、标准化的应用管理平台知识!(附网盘链接)
比特币一度突破14000美元,即将面临美国大选考验
你的财务报告该换个高级的套路了——财务分析驾驶舱
阿里云Q2营收破纪录背后,云的打开方式正在重塑
小程序入门到精通(二):了解小程序开发4个重要文件
Calculation script for time series data
随机推荐
Filecoin最新动态 完成重大升级 已实现四大项目进展!
大数据应用的重要性体现在方方面面
Using Es5 to realize the class of ES6
Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
DevOps是什么
Nodejs crawler captures ancient books and records, a total of 16000 pages, experience summary and project sharing
一篇文章带你了解CSS 渐变知识
Common algorithm interview has been out! Machine learning algorithm interview - KDnuggets
多机器人行情共享解决方案
(2)ASP.NET Core3.1 Ocelot路由
全球疫情加速互联网企业转型,区块链会是解药吗?
Process analysis of Python authentication mechanism based on JWT
Jmeter——ForEach Controller&Loop Controller
华为云“四个可靠”的方法论
Swagger 3.0 天天刷屏,真的香嗎?
Python crawler actual combat details: crawling home of pictures
Skywalking series blog 1 - install stand-alone skywalking
IPFS/Filecoin合法性:保护个人隐私不被泄露
vue-codemirror基本用法:实现搜索功能、代码折叠功能、获取编辑器值及时验证
小程序入门到精通(二):了解小程序开发4个重要文件