網站首頁 編程語言 正文
參數數量及其作用
該函數共有兩個參數,分別是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.
該函數的作用是從一個collection中取出全部變量,形成列個列表,key參數中輸入的是collection的名稱。
該函數常常與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函數tf.get_variable使用方法
原文鏈接:https://blog.csdn.net/weixin_44791964/article/details/96132749
相關推薦
- 2022-07-21 React中this指向問題
- 2023-05-30 Pandas.DataFrame行和列的轉置的實現_python
- 2022-12-30 解決React報錯useNavigate()?may?be?used?only?in?context
- 2022-11-01 JetPack?Compose底部導航欄的實現方法詳解_Android
- 2022-07-02 ansible模塊之include_tasks:為什么加了tags后導入的任務沒有執行?
- 2022-05-02 C++?多繼承詳情介紹_C 語言
- 2022-03-24 redis如何設置key的有效期_Redis
- 2024-02-01 前端訪問一個地址 地址上帶/api, 如何通過nginx 配置, 讓訪問后臺的時候是/而不是/api
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支