如何通过在tensorflow中运行tf.nn.dynamic\u rnn找到LSTM的中间输出

如何通过在tensorflow中运行tf.nn.dynamic\u rnn找到LSTM的中间输出,tensorflow,lstm,recurrent-neural-network,Tensorflow,Lstm,Recurrent Neural Network,我是tensorflow的新手,最近从各种博客上读到了关于LSTM的内容,如理解LSTM网络、Colah、递归神经网络的不合理有效性、Karparthy等 我在网上找到了以下代码: import numpy as np import tensorflow as tf def length(sequence): used = tf.sign(tf.reduce_max(tf.abs(sequence), reduction_indices=2)) length = tf.redu

我是tensorflow的新手,最近从各种博客上读到了关于LSTM的内容,如理解LSTM网络、Colah、递归神经网络的不合理有效性、Karparthy等

我在网上找到了以下代码:

import numpy as np
import tensorflow as tf

def length(sequence):
    used = tf.sign(tf.reduce_max(tf.abs(sequence), reduction_indices=2))
    length = tf.reduce_sum(used, reduction_indices=1)
    length = tf.cast(length, tf.int32)
    return length

num_neurons = 10
num_layers = 3
max_length = 8
frame_size = 5

# dropout = tf.placeholder(tf.float32)
cell = tf.contrib.rnn.LSTMCell(num_neurons, state_is_tuple= True)
# cell = DropoutWrapper(cell, output_keep_prob=dropout)
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers)

sequence = tf.placeholder(tf.float32, [None, max_length, frame_size])
output, state = tf.nn.dynamic_rnn(
    cell,
    sequence,
    dtype=tf.float32,
    sequence_length=length(sequence),
)

if __name__ == '__main__':
        sample = np.random.random((8, max_length, frame_size)) + 0.1
        # sample[np.ix_([0,1],range(50,max_length))] = 0
        # drop = 0.2
        with tf.Session() as sess:
                init_op = init_op = tf.global_variables_initializer()
                sess.run(init_op)
                o, s  = sess.run([output, state], feed_dict={sequence: sample})
                # print "Output shape is ", o.shape()
                # print "state shape is ", s.shape()
                print "Output is ", o
                print "State is ", s
对于上面的代码,state_is_tuple=True,我有一些疑问

问:tf.nn.dynamic\u rnn返回的输出和状态的简单含义是什么

我在网上读到,输出是最后一层在几个时间步和时间步的输出 国家是最终的国家

我的中间疑问是,“最后一层在几个时间步的输出”是什么意思

我研究了动态代码,因为我的主要任务是找到 ()

Q.**LSTM的所有中间输出都是通过调用dynamic\u rnn以与上述代码相同的方式完成的。我该怎么做呢

我还阅读了动态的内部调用。 此动态rnn返回最终输出和最终状态。除了最终输出。我想要所有的中间输出

我的目标是编写中定义的自定义动态rnn
请提供帮助。

如果有人能通过方框图向我解释整个图片(LSTM中的图层等),我将非常有效,我还不明白。关于tf.nn.dynamic\n返回值的第一个问题,请查看此处接受的答案:。对不起,剩下的我不知道怎么帮你。