Python tensorflow函数tf.get_collection用法是什么
Admin 2022-09-16 群英技术资讯 1350 次浏览
这篇文章给大家分享的是Python tensorflow函数tf.get_collection用法是什么。小编觉得挺实用的,因此分享给大家做个参考,文中的介绍得很详细,而要易于理解和学习,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。该函数共有两个参数,分别是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使用方法
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了如何利用Python快速统计文本的行数,要快速统计一个文本文件中的行数,其实就是要统计这个文本文件中换行符的个数,下面我们就一起进入文章看看具体的操作过程吧
所谓定时器,是指间隔特定时间执行特定任务的机制。几乎所有的编程语言,都有定时器的实现。这篇文章主要介绍的是通过Python实现的定时器,感兴趣的可以跟随小编学习一下
这篇文章主要介绍了pytorch 两个GPU同时训练的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
selenium的几种定位方法中,大杀器之一就是xpath方法,学会它,你将无所不能.本文就带大家详细了解一下这个大杀器,文中有非常详细的介绍,需要的朋友可以参考下
本文主要介绍了TensorFlow训练网络两种方式,一种是基于tensor(array),另外一种是迭代器,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008