Tensorflow 实战(-) 基础知识
来源:互联网 发布:大数据风控体系 编辑:程序博客网 时间:2024/06/05 06:58
1. tensorflow 介绍
1.1 设计理念
1) 图的定义与图的运行是分离开的
简单来说,就是定义了一个操作,但是并没有真正去运行,
tensorflow 被认为是一个符号主义的库。
编程模式分为命令式编程和符号式编程,
2) TensorFlow 中涉及的运算都在在图中,图的运算只能在session中,过程就是启动会话之后,用数据去填充节点,进行运算,关闭会话就不再进行计算。
2. tensorflow 变量作用域
2.1 variable_scope
只需要掌握两点: tf.variable_scope(<scope_name>) #创建域名
tf.get_variable(name, shape, dtype, initializer) # 通过名称创建或者返回一个变量
相关实例如下:
def test_scope(): with tf.variable_scope("scope1") as scope1: assert scope1.name == "scope1" v = tf.get_variable('v1', [1]) with tf.variable_scope(scope1, reuse=True): # #### reuse method v2 = tf.get_variable('v1', [1]) assert v == v2 with tf.variable_scope("foo", initializer=tf.constant_initializer(0.4)): mm = tf.get_variable("mm", [1]) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) x = sess.run(mm) print(x)
2.2 name_scope
name_scope 只对op和通过Variable创建的变量有作用,对get_variable的无影响。
def name_scope(): with tf.variable_scope("scope1"): with tf.name_scope("name_scope1"): v = tf.get_variable("v", [1]) b = tf.Variable(tf.zeros([1]), name='b') x = 1.0 + v assert v.name == "scope1/v:0" assert b.name == "scope1/name_scope1/b:0" assert x.op.name == "scope1/name_scope1/add"
阅读全文
0 0
- Tensorflow 实战(-) 基础知识
- TensorFlow技术解析与实战 4 基础知识
- TensorFlow 基础知识(笔记)
- tensorflow学习笔记(三):tensorflow 基础知识
- TensorFlow实战:Chapter-1(TensorFlow介绍)
- TensorFlow实战:Chapter-2(TensorFlow入门)
- Tensorflow基础知识总结(1)
- Tensorflow基础知识总结(2)
- TensorFlow实战(三)CNN
- tensorflow基础知识
- Tensorflow基础知识
- tensorflow基础知识
- Tensorflow基础知识
- TensorFlow实战
- TensorFlow实战
- Tensorflow学习笔记(一):基础知识
- TensorFlow基础知识5-会话(session)
- TensorFlow基础知识6-可视化(TensorBoard)
- 数据结构 -- 栈ADT
- HDU 5884 Sort (二分 贪心(k叉哈夫曼树))
- 给自己一个两年
- C# GDI+ 绘图
- 集合Collection
- Tensorflow 实战(-) 基础知识
- 简述生成式对抗网络
- 网络编程项目(聊天室项目)
- (function($) {…})(jQuery);
- 2.2logistic回归
- 线程安全、数据同步之synchronized与Lock
- Python笔记--默认参数最大的“坑”
- springboot 整合freemarker404问题
- webstorm配置sublime主题