18、使用 tf.app.flags 接口定义命令行参数
来源:互联网 发布:标书制作软件 编辑:程序博客网 时间:2024/05/19 22:44
一、使用 tf.app.flags 接口定义命令行参数
- 众所周知,深度学习有很多的
Hyperparameter
需要调优,TensorFlow 底层使用了python-gflags
项目,然后封装成tf.app.flags
接口 - 使用
tf.app.flags
接口可以非常方便的调用自带的DEFINE_string, DEFINE_boolean, DEFINE_integer, DEFINE_float
设置不同类型的命令行参数及其默认值,在实际项目中一般会提前定义命令行参数,如下所示:
# coding: utf-8# filename: flags.pyimport tensorflow as tf# 定义一个全局对象来获取参数的值,在程序中使用(eg:FLAGS.iteration)来引用参数FLAGS = tf.app.flags.FLAGS# 定义命令行参数,第一个是:参数名称,第二个是:参数默认值,第三个是:参数描述tf.app.flags.DEFINE_integer("iteration", 200000, "Iterations to train [2e5]")tf.app.flags.DEFINE_integer("disp_freq", 1000, "Display the current results every display_freq iterations [1e3]")tf.app.flags.DEFINE_integer("save_freq", 2000, "Save the checkpoints every save_freq iterations [2e3]")tf.app.flags.DEFINE_float("learning_rate", 0.001, "Learning rate of for adam [0.001]")tf.app.flags.DEFINE_integer("train_batch_size", 64, "The size of batch images [64]")tf.app.flags.DEFINE_integer("val_batch_size", 100, "The size of batch images [100]")tf.app.flags.DEFINE_integer("height", 48, "The height of image to use. [48]")tf.app.flags.DEFINE_integer("width", 160, "The width of image to use. [160]")tf.app.flags.DEFINE_integer("depth", 3, "Dimension of image color. [3]")tf.app.flags.DEFINE_string("data_dir", "/path/to/data_sets/", "Directory of dataset in the form of TFRecords.")tf.app.flags.DEFINE_string("checkpoint_dir", "/path/to/checkpoint_save_dir/", "Directory name to save the checkpoints [checkpoint]")tf.app.flags.DEFINE_string("model_name", "40w_grtr", "Model name. [40w_grtr]")tf.app.flags.DEFINE_string("gpu_id", "0", "Which GPU to be used. [0]")tf.app.flags.DEFINE_boolean("continue_train", False, "True for continue training.[False]")tf.app.flags.DEFINE_boolean("per_image_standardization", True, "True for per_image_standardization.[True]")# 定义主函数def main(argv=None): print(FLAGS.iteration) print(FLAGS.learning_rate) print(FLAGS.data_dir) print(FLAGS.continue_train)# 执行main函数if __name__ == '__main__': tf.app.run()
二、执行程序的方法
1、使用程序中的默认参数
python flags.py
2、在命令行更改程序中的默认参数
python flags.py --iteration=500000 --learning_rate=0.01 --data_dir='/home/test/' --continue_train=True
阅读全文
0 0
- 18、使用 tf.app.flags 接口定义命令行参数
- tensorflow(学习一)中的tf.app.flags函数定义命令行参数
- tensorflow-使用flags定义命令行参数
- tensorflow 学习(三)使用flags定义命令行参数
- Tensorflow学习(一)使用flags定义命令行参数
- TensorFlow中flags传递参数 解读tf.app.flags
- Tensorflow flags = tf.app.flags 的使用
- FLAGS = tf.app.flags.FLAGS
- tf.app.flags.DEFINE_string()和tf.app.flags.FLAGS
- TensorFlow 中 tf.app.flags.FLAGS 的用法介绍
- TensorFlow 学习(十三)—— tf.app.flags
- tf.flags.DEFINE_string
- SD卡 TF卡 接口引脚定义
- Tensorflow:tf.flags的用法
- RS232串行接口参数定义
- RS232串行接口参数定义
- (3)使用命令行参数
- //命令行参数使用。
- docker coentos7 tensorflow
- 习题6(6.13)
- [通过scikit-learn掌握机器学习] 02 线性回归
- C 自定义字符串输出
- Spiral Matrix II
- 18、使用 tf.app.flags 接口定义命令行参数
- C语言面向对象编程之一:封装与继承
- [Yii2 Widget]FancytreeWidget树状结构
- 19、TensorFlow 实现最近邻分类器(K=1)
- 过滤掉字符串中的非数字
- Leetcode350 Intersection of Two Arrays II &Leetcode Intersection of Two Arrays
- C语言面向对象编程之二:继承
- 20、TensorFlow 中 MNIST 数据集的使用
- 中山大学算法课程题目详解(第九周)