gpt4 book ai didi

python - RNN Cell 不存在于 tf.get_collection 中

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:55 25 4
gpt4 key购买 nike

使用 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

最佳答案

您尚未在 LSTMCell 上运行 __call__,这就是您看不到变量的原因。试试这个(我假设 batch_size=10rnn_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))

关于python - RNN Cell 不存在于 tf.get_collection 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41251428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com