我想更好地理解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()我得到以下信息:
以下代码定义了我的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)