python人工智能tensorflow函數(shù)tf.get_collection使用方法
參數(shù)數(shù)量及其作用
該函數(shù)共有兩個參數(shù),分別是key和scope。
def get_collection(key, scope=None)
Wrapper for Graph.get_collection() using the default graph.
See tf.Graph.get_collection for more details.
Args:
key: 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.
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.
該函數(shù)的作用是從一個collection中取出全部變量,形成列個列表,key參數(shù)中輸入的是collection的名稱。
該函數(shù)常常與tf.get_variable和tf.add_to_collection配合使用。
例子
該例子將分別舉例tf.get_collection與tf.get_variable和tf.add_to_collection的配合使用方法。
import tensorflow as tf;
import numpy as np;
c1 = ['c1', tf.GraphKeys.GLOBAL_VARIABLES]
v1 = tf.get_variable('v1', [1], initializer=tf.constant_initializer(1),collections=c1)
v2 = tf.get_variable('v2', [1], initializer=tf.constant_initializer(2))
tf.add_to_collection('c2', v2)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(tf.get_collection('c1'))
print(tf.get_collection('c2'))
其輸出為:
[<tf.Variable 'v1:0' shape=(1,) dtype=float32_ref>] [<tf.Variable 'v2:0' shape=(1,) dtype=float32_ref>]
tf.get_variable的用法可以參照我的另一篇博文:
python人工智能tensorflow函數(shù)tf.get_variable使用方法
以上就是python人工智能tensorflow函數(shù)tf.get_collection使用方法的詳細內(nèi)容,更多關(guān)于tensorflow函數(shù)tf.get_collection的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python調(diào)用騰訊云短信服務(wù)發(fā)送手機短信
這篇文章主要為大家介紹了Python調(diào)用騰訊云短信服務(wù)發(fā)送手機短信,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05
Python?實操顯示數(shù)據(jù)圖表并固定時間長度
這篇文章主要介紹了Python?實操顯示數(shù)據(jù)圖表并固定時間長度,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08
python opencv實現(xiàn)信用卡的數(shù)字識別
這篇文章主要介紹了python opencv實現(xiàn)信用卡的數(shù)字識別,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
詳解python執(zhí)行shell腳本創(chuàng)建用戶及相關(guān)操作
這篇文章主要介紹了python執(zhí)行shell腳本創(chuàng)建用戶及相關(guān)操作,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
python中dtypes和type()函數(shù)的區(qū)別示例詳解
type()是python內(nèi)置的函數(shù),type()返回數(shù)據(jù)結(jié)構(gòu)類型(list、dict、numpy.ndarray 等),dtype返回數(shù)據(jù)元素的數(shù)據(jù)類型(int、float等),這篇文章主要給大家介紹了關(guān)于python中dtypes和type()函數(shù)區(qū)別的相關(guān)資料,需要的朋友可以參考下2024-03-03
在Python的Django框架中更新數(shù)據(jù)庫數(shù)據(jù)的方法
這篇文章主要介紹了在Python的Django框架中更新數(shù)據(jù)庫數(shù)據(jù),對此Django框架中提供了便利的插入和更新方法,需要的朋友可以參考下2015-07-07

