python人工智能tensorflow函数tf.get_collection使用方法
作者:Bubbliiiing 时间:2023-08-09 14:27:54
参数数量及其作用
该函数共有两个参数,分别是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
标签:python,人工智能,tensorflow,tf.get,collection
0
投稿
猜你喜欢
xml文件调用css
2008-09-05 17:12:00
Oracle过程与函数的区别分析
2024-01-15 20:15:37
python调用cmd命令行制作刷博器
2023-07-26 15:18:35
Oracle数据库中SQL语句的优化技巧
2024-01-27 01:33:27
用ASP+CSS实现随机背景
2007-09-26 12:33:00
常见数据库系统比较 Oracle数据库
2024-01-26 04:18:57
Django rest framework分页接口实现原理解析
2023-08-22 21:26:36
vue+echarts实现动态折线图的方法与注意
2023-07-02 16:29:06
python程序快速缩进多行代码方法总结
2022-12-06 03:30:38
对python pandas 画移动平均线的方法详解
2023-11-16 04:21:33
探讨Mysql中OPTIMIZE TABLE的作用详解
2024-01-24 21:43:41
python按行读取文件,去掉每行的换行符\\n的实例
2022-06-01 03:49:43
详解python-docx处理Word必备工具
2023-10-03 03:15:08
VUE预渲染及遇到的坑
2023-07-02 17:08:34
php利用cookies实现购物车的方法
2023-07-23 08:32:37
Python爬取知乎图片代码实现解析
2023-02-22 08:14:14
python使用tkinter模块实现文件选择功能
2022-06-18 18:35:56
Python三元运算实现方法
2021-12-27 06:02:52
如何快速定位页面中复杂 CSS BUG 问题
2009-01-15 12:23:00
基于spring boot 日志(logback)报错的解决方式
2022-05-12 08:13:46