tensorflow之默认对象集合

使用tensorflow.add_collection()方法可以创建对象集合,而tensorflow默认会把对象放入名为“variables”的集合里面。
看代码:
import tensorflow as tf
import numpy as np

with tf.variable_scope(“xyz”) as scop:
a=tf.get_variable(“a”,shape=[2])
b=tf.get_variable(“b”,shape=[2])

c=tf.get_variable(“c”,shape=[2])

print(tf.get_collection(tf.GraphKeys.VARIABLES))

print(tf.GraphKeys.VARIABLES)

print(tf.get_collection(“variables”))
输出为:
[<tf.Variable ‘xyz/a:0’ shape=(2,) dtype=float32_ref>, <tf.Variable ‘xyz/b:0’ shape=(2,) dtype=float32_ref>, <tf.Variable ‘c:0’ shape=(2,) dtype=float32_ref>]
variables
[<tf.Variable ‘xyz/a:0’ shape=(2,) dtype=float32_ref>, <tf.Variable ‘xyz/b:0’ shape=(2,) dtype=float32_ref>, <tf.Variable ‘c:0’ shape=(2,) dtype=float32_ref>]

猜你喜欢

转载自blog.csdn.net/qq_33345917/article/details/84994515