当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Python3 e-learning case 4: writing web proxy
- EOS创始人BM: UE,UBI,URI有什么区别?
- Computer TCP / IP interview 10 even asked, how many can you withstand?
- (2)ASP.NET Core3.1 Ocelot路由
- Relationship between business policies, business rules, business processes and business master data - modern analysis
- 带你学习ES5中新增的方法
- xmppmini 專案詳解:一步一步從原理跟我學實用 xmpp 技術開發 4.字串解碼祕笈與訊息包
- 熬夜总结了报表自动化、数据可视化和挖掘的要点,和你想的不一样
- Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
- 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)
猜你喜欢
Elasticsearch database | elasticsearch-7.5.0 application construction
小程序入门到精通(二):了解小程序开发4个重要文件
Using Es5 to realize the class of ES6
TRON智能钱包PHP开发包【零TRX归集】
从海外进军中国,Rancher要执容器云市场牛耳 | 爱分析调研
[JMeter] two ways to realize interface Association: regular representation extractor and JSON extractor
Tool class under JUC package, its name is locksupport! Did you make it?
合约交易系统开发|智能合约交易平台搭建
中小微企业选择共享办公室怎么样?
IPFS/Filecoin合法性:保护个人隐私不被泄露
随机推荐
6.1.2 handlermapping mapping processor (2) (in-depth analysis of SSM and project practice)
教你轻松搞懂vue-codemirror的基本用法:主要实现代码编辑、验证提示、代码格式化
Cos start source code and creator
每个前端工程师都应该懂的前端性能优化总结:
從小公司進入大廠,我都做對了哪些事?
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
In depth understanding of the construction of Intelligent Recommendation System
向北京集结!OpenI/O 2020启智开发者大会进入倒计时
Leetcode's ransom letter
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
Swagger 3.0 天天刷屏,真的香嗎?
ES6学习笔记(四):教你轻松搞懂ES6的新增语法
Deep understanding of common methods of JS array
Python crawler actual combat details: crawling home of pictures
从海外进军中国,Rancher要执容器云市场牛耳 | 爱分析调研
Using Es5 to realize the class of ES6
A debate on whether flv should support hevc
git rebase的時候捅婁子了,怎麼辦?線上等……
Subordination judgment in structured data
前端都应懂的入门基础-github基础