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