#coding=utf-8
import tensorflow as tf
with tf.name_scope("hello") as name_scope:
arr1 = tf.get_variable("arr1", shape=[2,10],dtype=tf.float32)
a = tf.Variable(0,name='a')
arr2 = tf.get_variable('arr2', shape=[1,2], dtype=tf.float32)
collection = tf.get_collection(tf.GraphKeys().GLOBAL_VARIABLES,'a')#选取集合中名称开头为'a'的op
print(*collection)
结果:
<tf.Variable 'arr1:0' shape=(2, 10) dtype=float32_ref> <tf.Variable 'arr2:0' shape=(1, 2) dtype=float32_ref>