tf.identity的意义以及用例
来源:互联网 发布:android 仿淘宝购物车 编辑:程序博客网 时间:2024/05/21 23:31
最近在学习tensorflow,学到ExponentialMovingAverage时,里面有一个tf.identity操作,在Stack Overflow上看到一个很好的解释,记录一下。
原地址 : https://stackoverflow.com/questions/34877523/in-tensorflow-what-is-tf-identity-used-for
下面程序要做的是,5次循环,每次循环给x加1,赋值给y,然后打印出来
x = tf.Variable(0.0)#返回一个op,表示给变量x加1的操作x_plus_1 = tf.assign_add(x, 1)#control_dependencies的意义是,在执行with包含的内容(在这里就是 y = x)前#先执行control_dependencies中的内容(在这里就是 x_plus_1)with tf.control_dependencies([x_plus_1]): y = xinit = tf.initialize_all_variables()with tf.Session() as session: init.run() for i in xrange(5): print(y.eval())#相当于sess.run(y),由于control_dependencies的所以执行print前都会先执行x_plus_1
这个打印的是0,0,0,0,0 。也就是说没有达到我们预期的效果
如果改成这样:
x = tf.Variable(0.0)x_plus_1 = tf.assign_add(x, 1)with tf.control_dependencies([x_plus_1]): y = tf.identity(x)#修改部分init = tf.initialize_all_variables()with tf.Session() as session: init.run() for i in xrange(5): print(y.eval())This works: it prints 1, 2, 3, 4, 5.
这时候打印的是1,2,3,4,5
解释:
tf.identity是返回了一个一模一样新的tensor,再control_dependencies的作用块下,需要增加一个新节点到gragh中。有待更新。。。
阅读全文
0 0
- tf.identity的意义以及用例
- tf.identity()的理解
- tf.identity的作用
- tf.control_dependencies()和tf.identity()
- tf.control_dependencies与tf.identity组合详解
- 如何利用tf.add_to_collection、tf.get_collection以及tf.add_n来简化正则项的计算
- layout_weight的作用以及意义
- tensorflow学习——tf.get_collection(), tf.identity()
- 【tensorflow】scope的使用以及tf.Variable()和tf.get_variable()的区别
- tensorflow中embedding_lookup, tf.gather以及tf.nn.embedding_lookup_sparse的理解
- fork,vfork以及exec的意义
- 图像熵的意义以及计算
- 图像熵的意义以及计算
- CC1101之PATABLE的意义以及使用说明
- 立体匹配的研究背景以及意义
- 立体匹配的研究背景以及意义
- STM32 BOOT设置以及对应的意义
- java toString()方法以及重写的意义
- Ubuntu与windows-ssh反向隧道
- k6k4刷题-矩阵打印--螺旋状
- Macbook 中关于下载器和Youtube视频及字幕下载播放问题
- python3格式化输出
- CCF-训练50题-NO.2-图像旋转问题
- tf.identity的意义以及用例
- HDFS JAVA API操作
- iOS 常用的宏定义
- NUIST OJ 1350-1352 面朝大海,春暖花开【初识线段树】
- 剑指offer 从尾到头打印链表
- Python数据类型:列表
- for 创建一个方法:键盘录入一个数 ,求它的 阶乘 及 阶乘的和
- GoldenGate 传统抽取进程随 DataGuard 主备快速切换的方案(ADG 模式)
- [POJ] 2528