【发布时间】:2019-07-24 11:17:43
【问题描述】:
我正在尝试计算 LSTM 模型的总参数,我有些困惑。
我搜索了一些答案,例如this post和this post。我不知道隐藏单元在参数计算中的作用是什么(在我的例子中是 h1=64,h2=128)。
import tensorflow as tf
b, t, d_in, d_out = 32, 256, 161, 257
data = tf.placeholder("float", [b, t, d_in]) # [batch, timestep, dim_in]
labels = tf.placeholder("float", [b, t, d_out]) # [batch, timestep, dim_out]
myinput = data
batch_size, seq_len, dim_in = myinput.shape
rnn_layers = []
h1 = 64
c1 = tf.nn.rnn_cell.LSTMCell(h1)
rnn_layers.append(c1)
h2 = 128
c2 = tf.nn.rnn_cell.LSTMCell(h1)
rnn_layers.append(c2)
multi_rnn_cell = tf.nn.rnn_cell.MultiRNNCell(rnn_layers)
rnnoutput, state = tf.nn.dynamic_rnn(cell=multi_rnn_cell,
inputs=myinput, dtype=tf.float32)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
all_trainable_vars = tf.reduce_sum([tf.reduce_prod(v.shape) for v in tf.trainable_variables()])
print(sess.run(all_trainable_vars))
我用Tensorflow打印了参数总数,显示一个参数的总数是90880。我怎样才能一步一步得到这个结果,谢谢
【问题讨论】:
标签: tensorflow deep-learning lstm