使用tf.get_collection()
时,RNN单元格未显示。我错过了什么?
import tensorflow as tf
print(tf.__version__)
rnn_cell = tf.nn.rnn_cell.LSTMCell(16)
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
other_var = tf.Variable(0)
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
打印出来
0.12.0
[]
[<tensorflow.python.ops.variables.Variable object at 0x0000027961250B70>]
Windows 10,Python 3.5
答案 0 :(得分:2)
您尚未在__call__
上运行LSTMCell
,这就是您没有看到变量的原因。试试这个(我假设batch_size=10
和rnn_size=16
)
import tensorflow as tf
print(tf.__version__)
rnn_cell = tf.nn.rnn_cell.LSTMCell(16)
a = tf.placeholder(tf.float32, [10, 16])
zero = rnn_cell.zero_state(10,tf.float32)
# The variables are created in the following __call__
b = rnn_cell(a, zero)
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
other_var = tf.Variable(0)
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))