本文来源:http://blog.csdn.net/u012436149/article/details/53894354

tensorflow  之  collection

tensorflowcollection提供一个全局的存储机制,不会受到变量名生存空间的影响。一处保存,到处可取。

  
 #向collection中存数据
tf.Graph.add_to_collection(name, value) #Stores value in the collection with the given name.
#Note that collections are not sets, so it is possible to add a value to a collection
#several times.
# 注意,一个‘name’下,可以存很多值; add_to_collection("haha", [a,b]),这种情况下
#tf.get_collection("haha")获得的是 [[a,b]], 并不是[a,b]
tf.add_to_collection(name, value)
#这个和上面函数功能上没有区别,区别是,这个函数是给默认图使用的
#从collection中获取数据
tf.Graph.get_collection(name, scope=None) Returns a list of values in the collection with the given name. This is different from get_collection_ref() which always returns the actual
collection list if it exists in that it returns a new list each time it is called. Args: name: The key for the collection. For example, the GraphKeys class contains many
standard names for collections.
scope: (Optional.) If supplied, the resulting list is filtered to include only
items whose name attribute matches using re.match. Items without a name attribute
are never returned if a scope is supplied and the choice or re.match means that
a scope without special tokens filters by prefix.
#返回re.match(r"scope", item.name)匹配成功的item, re.match(从字符串的开始匹配一个模式)
Returns: The list of values in the collection with the given name, or an empty list if no
value has been added to that collection. The list contains the values in the
order under which they were collected.

实例:

v4 = tf.get_variable(name='v4', shape=[1], collections=[tf.GraphKeys.GLOBAL_VARIABLES , 'positives'],initializer=tf.constant_initializer(3))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(tf.get_collection('positives'))

>>

<tf.Variable 'v4:0' shape=(1,) dtype=float32_ref>]

Tensorlfow学习笔记----collection的更多相关文章

  1. Java学习笔记--Collection和Collections的区别

    转自 http://pengcqu.iteye.com/blog/492196 比较Collection 和Collections的区别.   1.java.util.Collection 是一个集合 ...

  2. Backbone学习笔记 - Collection及Router篇

    Collection Collection可以看成是Model的集合.以下是一个集合的例子: var Song = Backbone.Model.extend({ defaults: { name: ...

  3. java学习笔记——Collection集合接口

    NO 方法名称 描述 1 public boolean add(E e) 向集合中保存数据 2 public void clear() 清空集合 3 public boolean contains(O ...

  4. JavaSE中Collection集合框架学习笔记(2)——拒绝重复内容的Set和支持队列操作的Queue

    前言:俗话说“金三银四铜五”,不知道我要在这段时间找工作会不会很艰难.不管了,工作三年之后就当给自己放个暑假. 面试当中Collection(集合)是基础重点.我在网上看了几篇讲Collection的 ...

  5. JavaSE中Collection集合框架学习笔记(3)——遍历对象的Iterator和收集对象后的排序

    前言:暑期应该开始了,因为小区对面的小学这两天早上都没有像以往那样一到七八点钟就人声喧闹.车水马龙. 前两篇文章介绍了Collection框架的主要接口和常用类,例如List.Set.Queue,和A ...

  6. ASP.Net开发基础温故知新学习笔记

    申明:本文是学习2014版ASP.Net视频教程的学习笔记,仅供本人复习之用,也没有发布到博客园首页. 一.一般处理程序基础 (1)表单提交注意点: ①GET通过URL,POST通过报文体: ②需在H ...

  7. 《Java学习笔记(第8版)》学习指导

    <Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多 ...

  8. JavaScript闭包(Closure)学习笔记

    闭包(closure)是JavaScript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 下面就是我的学习笔记,对于JavaScript初学者应该是很有用的. 一.变量的作用域 要理解 ...

  9. 两千行PHP学习笔记

    亲们,如约而至的PHP笔记来啦~绝对干货! 以下为我以前学PHP时做的笔记,时不时的也会添加一些基础知识点进去,有时还翻出来查查. MySQL笔记:一千行MySQL学习笔记http://www.cnb ...

随机推荐

  1. oracle学习 第一章 简单的查询语句 ——03

    1.1最简单的查询语句 例 1-1 SQL> select * from emp; 例 1-1 结果 这里的 * 号表示全部的列.它与在select 之后列出全部的列名是一样的.查询语句以分号( ...

  2. 漫谈linux之文件IO篇(SSD写性能和机械硬盘差不多,读是4到10倍)

    前同事的文章,觉得写得很清晰,收藏了. http://blog.chinaunix.net/uid-27105712-id-3270102.html 在Linux 开发中,有几个关系到性能的东西,技术 ...

  3. 青蛙的约会 poj 1061

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 86640   Accepted: 15232 Descripti ...

  4. 35.自己实现vector模板库myvector

    myvector.h #pragma once //自己写的vector模板库 template <class T> class myvector { public: //构造 myvec ...

  5. PostgreSQL服务器存储参数的内部查看方法和实际表述之间的关系

    postgres=# show wal_buffers ; wal_buffers ------------- 4MB(1 row) postgres=# show port; port ------ ...

  6. SQL流程控制语句

    1 GoTo语句 IF 12>9GOTO print1ELSE GOTO print2 print1:PRINT '执行了流程1'--GOTO theEndprint2:PRINT '执行了流程 ...

  7. 洛谷 P3804 【模板】后缀自动机 统计单词出现次数

    后缀自动机模板题. 关键时求解每个节点的 $right$ 大小. 由于后缀自动机在构建时会保证点和点的 $right$ 只可能没有交集,或者一个是另一个的真子集,我们可以不重复的对 $right$ 进 ...

  8. JS获取当前时间(YYYY-MM-DD ),element显示默认当前时间,显示默认昨天,显示默认上个月

    原文链接:点我 进来的随便看看,或许有帮助 vue+element-ui   datepicker 设置默认日期用的框架是vue+element-ui ,以下是时间控件 <el-form-ite ...

  9. 洛谷3933 Chtholly Nota Seniorious 二分答案+贪心

    题目链接 题意 给你一个N*M的矩阵 (N,M <=2000)  把他分成两部分 使两部分的极差较大的一个最小  求这个最小值.然后分矩阵的要求是:每个部分内部的方块之间,可以通过上下左右相互到 ...

  10. Android开发之Menu:OptionMenu(选项菜单)、ContextMenu(上下文菜单)、SubMenu(子菜单)

    菜单的概念,现在已经很普及了.Windows系统.Mac.桌面版Linux.Java Swing等,都有可视化菜单.一.Android平台3种菜单  选项菜单(OptionMenu).上下文菜单(Co ...