当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Calculation script for time series data
- 快快使用ModelArts,零基础小白也能玩转AI!
- Cos start source code and creator
- 中小微企业选择共享办公室怎么样?
- ES6学习笔记(五):轻松了解ES6的内置扩展对象
- Tool class under JUC package, its name is locksupport! Did you make it?
- Python crawler actual combat details: crawling home of pictures
- 业内首发车道级导航背后——详解高精定位技术演进与场景应用
- 如何玩转sortablejs-vuedraggable实现表单嵌套拖拽功能
- 阿里云Q2营收破纪录背后,云的打开方式正在重塑
猜你喜欢
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
每个前端工程师都应该懂的前端性能优化总结:
Thoughts on interview of Ali CCO project team
ES6学习笔记(四):教你轻松搞懂ES6的新增语法
容联完成1.25亿美元F轮融资
钻石标准--Diamond Standard
JVM memory area and garbage collection
It's so embarrassing, fans broke ten thousand, used for a year!
Didi elasticsearch cluster cross version upgrade and platform reconfiguration
[JMeter] two ways to realize interface Association: regular representation extractor and JSON extractor
随机推荐
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
What is the difference between data scientists and machine learning engineers? - kdnuggets
Synchronous configuration from git to consult with git 2consul
Python3 e-learning case 4: writing web proxy
htmlcss
ES6学习笔记(四):教你轻松搞懂ES6的新增语法
数据产品不就是报表吗?大错特错!这分类里有大学问
快快使用ModelArts,零基礎小白也能玩轉AI!
Calculation script for time series data
A debate on whether flv should support hevc
How to become a data scientist? - kdnuggets
2019年的一个小目标,成为csdn的博客专家,纪念一下
教你轻松搞懂vue-codemirror的基本用法:主要实现代码编辑、验证提示、代码格式化
6.1.1 handlermapping mapping processor (1) (in-depth analysis of SSM and project practice)
Grouping operation aligned with specified datum
Use of vuepress
合约交易系统开发|智能合约交易平台搭建
axios学习笔记(二):轻松弄懂XHR的使用及如何封装简易axios
Process analysis of Python authentication mechanism based on JWT
采购供应商系统是什么?采购供应商管理平台解决方案