当前位置:网站首页>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
![WeChat ID](/img/34/9adf494c3b8ebae9000d451f12eb02.jpg)
版权声明
本文为[Elementary school students in IT field]所创,转载请带上原文链接,感谢
边栏推荐
- Serilog原始碼解析——使用方法
- Didi elasticsearch cluster cross version upgrade and platform reconfiguration
- Examples of unconventional aggregation
- 至联云解析:IPFS/Filecoin挖矿为什么这么难?
- Classical dynamic programming: complete knapsack problem
- ES6 essence:
- Calculation script for time series data
- Did you blog today?
- “颜值经济”的野望:华熙生物净利率六连降,收购案遭上交所问询
- 华为云“四个可靠”的方法论
猜你喜欢
如何玩转sortablejs-vuedraggable实现表单嵌套拖拽功能
Jmeter——ForEach Controller&Loop Controller
一篇文章带你了解CSS 渐变知识
如何将数据变成资产?吸引数据科学家
Vue 3 responsive Foundation
使用 Iceberg on Kubernetes 打造新一代云原生数据湖
Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
axios学习笔记(二):轻松弄懂XHR的使用及如何封装简易axios
全球疫情加速互联网企业转型,区块链会是解药吗?
Existence judgment in structured data
随机推荐
全球疫情加速互联网企业转型,区块链会是解药吗?
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
After reading this article, I understand a lot of webpack scaffolding
CCR炒币机器人:“比特币”数字货币的大佬,你不得不了解的知识
How to get started with new HTML5 (2)
6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
钻石标准--Diamond Standard
6.2 handleradapter adapter processor (in-depth analysis of SSM and project practice)
Linked blocking Queue Analysis of blocking queue
一篇文章带你了解CSS3圆角知识
What is the difference between data scientists and machine learning engineers? - kdnuggets
H5 makes its own video player (JS Part 2)
6.1.2 handlermapping mapping processor (2) (in-depth analysis of SSM and project practice)
Save the file directly to Google drive and download it back ten times faster
[JMeter] two ways to realize interface Association: regular representation extractor and JSON extractor
阿里云Q2营收破纪录背后,云的打开方式正在重塑
业内首发车道级导航背后——详解高精定位技术演进与场景应用
Network security engineer Demo: the original * * is to get your computer administrator rights! 【***】
TRON智能钱包PHP开发包【零TRX归集】
深度揭祕垃圾回收底層,這次讓你徹底弄懂她