您现在的位置是:网站首页> 编程资料编程资料
python人工智能tensorflow函数tf.get_collection使用方法_python_
2023-05-26
368人已围观
简介 python人工智能tensorflow函数tf.get_collection使用方法_python_
参数数量及其作用
该函数共有两个参数,分别是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.get_variable的用法可以参照我的另一篇博文:
python人工智能tensorflow函数tf.get_variable使用方法
以上就是python人工智能tensorflow函数tf.get_collection使用方法的详细内容,更多关于tensorflow函数tf.get_collection的资料请关注其它相关文章!
您可能感兴趣的文章:
相关内容
- python中py文件与pyc文件相互转换的方法实例_python_
- Python自定义模块的创建与使用_python_
- python链表的基础概念和基础用法详解_python_
- python循环神经网络RNN函数tf.nn.dynamic_rnn使用_python_
- 利用python实现你说我猜游戏的完整实例_python_
- python人工智能tensorflow构建卷积神经网络CNN_python_
- python版单链表反转_python_
- python打印经典故事从前有座山的几种写法_python_
- python人工智能tensorflow构建循环神经网络RNN_python_
- Python利用shutil模块实现文件的裁剪与压缩_python_
