小编pro*_*_93的帖子

了解Tensorflow BasicLSTMCell内核和偏置形状

我想更好地理解Tensorflow的BasicLSTMCell Kernel和Bias的形状。

@tf_export("nn.rnn_cell.BasicLSTMCell")
class BasicLSTMCell(LayerRNNCell):

input_depth = inputs_shape[1].value
h_depth = self._num_units
self._kernel = self.add_variable(
    _WEIGHTS_VARIABLE_NAME,
    shape=[input_depth + h_depth, 4 * self._num_units])
self._bias = self.add_variable(
    _BIAS_VARIABLE_NAME,
    shape=[4 * self._num_units],
    initializer=init_ops.zeros_initializer(dtype=self.dtype))
Run Code Online (Sandbox Code Playgroud)

为什么内核的形状为[input_depth + h_depth,4 * self._num_units]),而偏向形状为[4 * self._num_units]?也许因子4来自忘记门,块输入,输入门和输出门?那么,将input_depth和h_depth相加的原因是什么?

有关我的LSTM网络的更多信息:

num_input = 12,时间步长= 820,num_hidden = 64,num_classes = 2。

使用tf.trainables_variables()我得到以下信息:

  • 变量名称:变量:0形状:(64,2)参数:128
  • 变量名称:Variable_1:0 Shape:(2,)Parameters:2
  • 变量名称:rnn / basic_lstm_cell /内核:0形状:(76,256)参数:19456
  • 变量名称:rnn / basic_lstm_cell / bias:0形状:(256,)参数:256

以下代码定义了我的LSTM网络。

def RNN(x, weights, biases):

    x = tf.unstack(x, timesteps, 1)
    lstm_cell = rnn.BasicLSTMCell(num_hidden)
    outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)

    return tf.matmul(outputs[-1], weights['out']) …
Run Code Online (Sandbox Code Playgroud)

machine-learning deep-learning lstm tensorflow rnn

4
推荐指数
1
解决办法
494
查看次数

标签 统计

deep-learning ×1

lstm ×1

machine-learning ×1

rnn ×1

tensorflow ×1