tensorflow 使用flags定义命令行参数的方法
作者:一个人的场域 时间:2021-03-20 10:43:23
tf定义了tf.app.flags,用于支持接受命令行传递参数,相当于接受argv。
import tensorflow as tf
#第一个是参数名称,第二个参数是默认值,第三个是参数描述
tf.app.flags.DEFINE_string('str_name', 'def_v_1',"descrip1")
tf.app.flags.DEFINE_integer('int_name', 10,"descript2")
tf.app.flags.DEFINE_boolean('bool_name', False, "descript3")
FLAGS = tf.app.flags.FLAGS
#必须带参数,否则:'TypeError: main() takes no arguments (1 given)'; main的参数名随意定义,无要求
def main(_):
print(FLAGS.str_name)
print(FLAGS.int_name)
print(FLAGS.bool_name)
if __name__ == '__main__':
tf.app.run() #执行main函数
执行:
[root@AliHPC-G41-211 test]# python tt.py
def_v_1
10
False
[root@AliHPC-G41-211 test]# python tt.py --str_name test_str --int_name 99 --bool_name True
test_str
99
True
来源:https://blog.csdn.net/leiting_imecas/article/details/72367937
标签:tensorflow,flags
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Python绘制3D立体爱心图案的示例详解
2021-04-03 18:05:09
![](https://img.aspxhome.com/file/2023/3/68263_0s.png)
CentOS 7 安装python3.7.1的方法及注意事项
2023-03-10 21:23:53
python七种方法判断字符串是否包含子串
2023-09-19 04:06:20
windows下python 3.6.4安装配置图文教程
2023-08-10 02:57:37
![](https://img.aspxhome.com/file/2023/7/77827_0s.jpg)
一个统计当前在线用户的解决方案
2007-10-13 19:27:00
PHP面向对象程序设计高级特性详解(接口,继承,抽象类,析构,克隆等)
2023-11-23 11:35:00
CSS编写过程中常见的10个错误
2008-05-29 12:49:00
python实现自动化上线脚本的示例
2021-02-01 05:14:49
Python交换字典键值对的四种方法实例
2022-11-10 04:34:04
tensorflow 初始化未初始化的变量实例
2021-05-16 13:47:54
Python timer定时器两种常用方法解析
2023-07-21 19:20:56
使用Python脚本将绝对url替换为相对url的教程
2022-09-03 09:36:39
Oracle9i取得建表和索引的DDL语句
2010-07-20 12:59:00
在Linux系统上通过uWSGI配置Nginx+Python环境的教程
2023-01-05 22:25:57
pytorch 如何使用float64训练
2023-08-12 00:19:45
![](https://img.aspxhome.com/file/2023/5/64675_0s.png)
PHP中使用Memache作为进程锁的操作类分享
2023-11-22 18:10:02
深底色页面设计指南[译]
2009-08-06 18:16:00
![](https://img.aspxhome.com/file/UploadPic/20098/6/darkdesign1-79s.jpg)
SQL Server 2005中的CLR集成
2009-03-10 15:07:00
python实现通讯录管理系统
2022-01-31 08:25:31
js序列化和反序列化的使用讲解
2023-08-05 08:13:24