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)
不行,返回[]