tf.add_to_collection:把变量放入一个集合,把很多变量变成一个列表

tf.get_collection:从一个结合中取出全部变量,是一个列表

tf.add_n:把一个列表的东西都依次加起来

例如:

import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt; v1 = tf.get_variable(name='v1', shape=[1], initializer=tf.constant_initializer(0))
tf.add_to_collection('loss', v1)
v2 = tf.get_variable(name='v2', shape=[1], initializer=tf.constant_initializer(2))
tf.add_to_collection('loss', v2) with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print tf.get_collection('loss')
print sess.run(tf.add_n(tf.get_collection('loss')))

输出:
[<tensorflow.python.ops.variables.Variable object at 0x7f6b5d700c50>, <tensorflow.python.ops.variables.Variable object at 0x7f6b5d700c90>]
[ 2.]

最新文章

  1. Shell命令_smem
  2. LeetCode之136. Single Number
  3. 实战Java虚拟机之三“G1的新生代GC”
  4. outline使用方法,outline与border的区别:
  5. 如何让iOS 保持界面流畅?这些技巧你知道吗
  6. jQuery Ajax无刷新操作一般处理程序 ashx
  7. Javascript样例之文档章节滚动全版(DOM)
  8. ios 中的小技巧 - 总有你想要的 一
  9. placeholder 兼容IE9以下版本 包含pasword
  10. Hdu 4738【求无向图的桥】.cpp
  11. python基础操作_文件读写操作
  12. LeetCode题解38.Count and Say
  13. android setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds区别
  14. 70个Python练手项目列表(都有完整教程)
  15. 链接中 href=&#39;#&#39; 和 href=&#39;###&#39; 的区别
  16. mysql中count的注意事项
  17. Swift学习笔记4
  18. MySQL中adddate学习
  19. [Laravel] 04 - Blade templates
  20. Failed to execute request because the App-Domain could not be created. Error: 0x80070002 系统找不到指定的文件。

热门文章

  1. 【LeetCode】拓扑排序 topological-sort(共5题)
  2. java ArrayList的几种方法使用
  3. ERROR=(CODE=1153)
  4. restful接口风格
  5. json序列化反序列
  6. angualr项目引入容联 七陌7mroo
  7. (转)docker run的--rm选项详解
  8. (66) c# async await
  9. 命令连接redis
  10. Linux用户空间与内核地址空间