如何使用4维输入输入LSTM? [英] How to feed into LSTM with 4 dimensional input?

查看:214
本文介绍了如何使用4维输入输入LSTM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的序列输入:(6000, 64, 100, 50)

I have a sequence input in this shape: (6000, 64, 100, 50)

6000只是样本序列的数量.每个序列的长度为64.

The 6000 is just the number of sample sequences. Each sequences is 64 in length.

我计划使用Keras将这个输入适合LSTM.

I plan to fit this input into an LSTM using Keras.

我通过以下方式设置输入:

I setup my input this way:

input = Input(shape=(64, 100, 50))

这为我提供了(?, 64, 100, 50)

但是,当我像这样将input放入我的LSTM中时:

However, when I put input into my LSTM like so:

x = LSTM(256, return_sequences=True)(input)

我收到此错误:

输入0与lstm_37层不兼容:找到预期的ndim = 3 ndim = 4

Input 0 is incompatible with layer lstm_37: expected ndim=3, found ndim=4

如果我的输入形状像(?, 64, 100)一样,这将奏效,但是当我具有第4维时,则不行.

This would have worked if my input shape was something like (?, 64, 100), but not when I've a 4th dimension.

这是否意味着LSTM只能接受3维输入?如何使用Keras将4维甚至更高维的输入输入LSTM?

Does this mean that LSTM can only take an input of 3 dimensional? How can I feed a 4 or even higher dimension input into LSTM using Keras?

推荐答案

答案是你不能.

Keras文档为递归层提供了以下信息:

The Keras Documentation provides the following information for Recurrent Layer:

输入形状

形状为(batch_size, timesteps, input_dim)的3D张量.

在您的情况下,您有64个时间步,每个步的形状(100,50).使模型正常工作的最简单方法是将数据重塑为(100 * 50).

In your case you have 64 timesteps where each step is of shape (100, 50). The easiest way to get the model working is to reshape your data to (100*50).

Numpy提供了一个简单的功能:

Numpy provides an easy function to do so:

X = numpy.zeros((6000, 64, 100, 50), dtype=numpy.uint8)
X = numpy.reshape(X, (6000, 64, 100*50))

这合理与否很大程度上取决于您的数据.

Wheter this is reasonable or not highly depends on your data.

这篇关于如何使用4维输入输入LSTM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆