当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Troubleshooting and summary of JVM Metaspace memory overflow
- 做外包真的很难,身为外包的我也无奈叹息。
- 6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
- vue-codemirror基本用法:实现搜索功能、代码折叠功能、获取编辑器值及时验证
- Arrangement of basic knowledge points
- Skywalking series blog 5-apm-customize-enhance-plugin
- Skywalking series blog 1 - install stand-alone skywalking
- hadoop 命令总结
- Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
- Network security engineer Demo: the original * * is to get your computer administrator rights! 【***】
猜你喜欢
How long does it take you to work out an object-oriented programming interview question from Ali school?
JVM memory area and garbage collection
It's so embarrassing, fans broke ten thousand, used for a year!
你的财务报告该换个高级的套路了——财务分析驾驶舱
TRON智能钱包PHP开发包【零TRX归集】
Summary of common algorithms of binary tree
人工智能学什么课程?它将替代人类工作?
中国提出的AI方法影响越来越大,天大等从大量文献中挖掘AI发展规律
一篇文章带你了解CSS对齐方式
What is the side effect free method? How to name it? - Mario
随机推荐
Grouping operation aligned with specified datum
Calculation script for time series data
Jmeter——ForEach Controller&Loop Controller
教你轻松搞懂vue-codemirror的基本用法:主要实现代码编辑、验证提示、代码格式化
EOS创始人BM: UE,UBI,URI有什么区别?
Tool class under JUC package, its name is locksupport! Did you make it?
JVM memory area and garbage collection
Elasticsearch 第六篇:聚合統計查詢
I think it is necessary to write a general idempotent component
Deep understanding of common methods of JS array
[JMeter] two ways to realize interface Association: regular representation extractor and JSON extractor
Classical dynamic programming: complete knapsack problem
ES6学习笔记(五):轻松了解ES6的内置扩展对象
hadoop 命令总结
After reading this article, I understand a lot of webpack scaffolding
Skywalking series blog 2-skywalking using
基於MVC的RESTFul風格API實戰
How long does it take you to work out an object-oriented programming interview question from Ali school?
Existence judgment in structured data
Flink on paasta: yelp's new stream processing platform running on kubernetes