zoukankan      html  css  js  c++  java
  • Tensorlfow学习笔记----collection

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

    tensorflow  之  collection

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

      
     1 #向collection中存数据
     2 tf.Graph.add_to_collection(name, value)
     3 
     4 #Stores value in the collection with the given name.
     5 #Note that collections are not sets, so it is possible to add a value to a collection
     6 #several times.
     7 # 注意,一个‘name’下,可以存很多值; add_to_collection("haha", [a,b]),这种情况下
     8 #tf.get_collection("haha")获得的是 [[a,b]], 并不是[a,b]
     9 tf.add_to_collection(name, value)
    10 #这个和上面函数功能上没有区别,区别是,这个函数是给默认图使用的
    #从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>]
  • 相关阅读:
    P2114 [NOI2014]起床困难综合症(二进制)
    P4577 [FJOI2018]领导集团问题
    P5290 [十二省联考2019]春节十二响(堆+启发式合并)
    P2048 [NOI2010]超级钢琴(RMQ+堆+贪心)
    P4890 Never·island(dp)
    P2617 Dynamic Rankings(树状数组套主席树)
    P5241 序列(滚动数组+前缀和优化dp)
    P3243 [HNOI2015]菜肴制作(拓扑排序)
    【LeetCode每天一题】Combination Sum II(组合和II)
    【LeetCode每天一题】Combination Sum(组合和)
  • 原文地址:https://www.cnblogs.com/lyc-seu/p/8565654.html
Copyright © 2011-2022 走看看