name_scope和variable_scope 在定义tensor的时候都会在name前面加上前缀,但是在使用
tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=scope)
的使用之后配合variable_scope才能获得对应的tensor list。
例如
with tf.variable_scope(scope,reuse=reuse):
flat_state = tf.layers.flatten(state)
out = tf.layers.dense(flat_state, num_actions)
tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=scope)
可以获得这两个tensor的list
但是
with tf.name_scope(scope,reuse=reuse):
flat_state = tf.layers.flatten(state)
out = tf.layers.dense(flat_state, num_actions)
tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=scope)
不行,返回[]