Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Tensorflow中将CNN输出传递给LSTM?_Tensorflow_Lstm_Convolution - Fatal编程技术网

在Tensorflow中将CNN输出传递给LSTM?

在Tensorflow中将CNN输出传递给LSTM?,tensorflow,lstm,convolution,Tensorflow,Lstm,Convolution,假设CNN的输出形状为[批次大小、高度、宽度、通道数](假设格式为通道数最后一次),我有以下方法将CNN维度转换为RNN维度: def collapse_to_rnn_dims(inputs): batch_size, height, width, num_channels = inputs.get_shape().as_list() if batch_size is None: batch_size = -1 return tf.reshape(inpu

假设CNN的输出形状为
[批次大小、高度、宽度、通道数]
(假设格式为
通道数最后一次
),我有以下方法将CNN维度转换为RNN维度:

def collapse_to_rnn_dims(inputs):
    batch_size, height, width, num_channels = inputs.get_shape().as_list()
    if batch_size is None:
        batch_size = -1
    return tf.reshape(inputs, [batch_size, width, height * num_channels])
它确实有效。然而,我只是想问一下,这是否真的是重塑CNN输出的正确方法,以便它们可以传递到LSTM层。

我找到了一个答案,它与我在手写文本识别中所做的完全相同,尽管这个答案假设
时间步数
(宽度)是动态的,而不是批大小

shape = cnn_net.get_shape().as_list()  # [batch, height, width, features]
transposed = tf.transpose(cnn_net, perm=[0, 2, 1, 3],
                          name='transposed')  # [batch, width, height, features]
conv_reshaped = tf.reshape(transposed, [shape[0], -1, shape[1] * shape[3]],
                           name='reshaped')  # [batch, width, height x features]

您可以简单地采用重塑操作: