值:LSTM_14层的输入0与图层不兼容:预期ndim = 3,找到ndim = 4。收到完整的形状:[NONE,12,12,64]

发布于 2025-01-23 12:27:26 字数 825 浏览 0 评论 0原文

我正在使用CNN-LSTM网络进行图像分类。我的图像大小为(224、224、3),批处理大小为90。当我将输入传递到LSTM层时,我会遇到此错误。以下是我的代码片段:

input1 = Input(shape=(224, 224,3))
x = Conv2D(8, (3,3), activation ="relu")(input1)
x = MaxPooling2D(2,2)(x)
x = Conv2D(16, (3,3), activation ="relu")(x)
x = MaxPooling2D(2,2)(x)
x = Conv2D(32, (3,3), activation ="relu")(x)
x = MaxPooling2D(2,2)(x)
x = Conv2D(64, (3,3), activation ="relu")(x)
x = Dropout(0.2)(x)
x = MaxPooling2D(2,2)(x)
x = LSTM(units= 64, activation= 'tanh', input_shape= [None, 144], return_sequences = True)(x)

error:
---> 10 x = LSTM(units= 64, activation= 'tanh', input_shape= [None, 144], return_sequences = True)(x)
ValueError: Input 0 of layer lstm_14 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: [None, 12, 12, 64]

感谢有人可以对我的问题进行整理。

I am using CNN-LSTM network for image classification. My image size is (224, 224, 3) and batch size is 90. I m getting this error when i passing input to LSTM layer. Following is my code snippet:

input1 = Input(shape=(224, 224,3))
x = Conv2D(8, (3,3), activation ="relu")(input1)
x = MaxPooling2D(2,2)(x)
x = Conv2D(16, (3,3), activation ="relu")(x)
x = MaxPooling2D(2,2)(x)
x = Conv2D(32, (3,3), activation ="relu")(x)
x = MaxPooling2D(2,2)(x)
x = Conv2D(64, (3,3), activation ="relu")(x)
x = Dropout(0.2)(x)
x = MaxPooling2D(2,2)(x)
x = LSTM(units= 64, activation= 'tanh', input_shape= [None, 144], return_sequences = True)(x)

error:
---> 10 x = LSTM(units= 64, activation= 'tanh', input_shape= [None, 144], return_sequences = True)(x)
ValueError: Input 0 of layer lstm_14 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: [None, 12, 12, 64]

Thanks if someone can sort my issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2025-01-30 12:27:26

根据 documentation>文档页面以下形状:[批处理,时间段,功能]。您的LSTM层接收到形状的输入[NONE,12,12,64],这就是为什么您获得有关3D/4D形状的错误的原因。您需要重塑张量:[NONE,12,12,64] - > [无,144,64]。为此,您可以插入 reshape layer 您的最后一个maxpooling2dlstm层。

According to the documentation page, LSTM layer input should have the following shape: [batch, timesteps, feature]. Your LSTM layer receives input of shape [None, 12, 12, 64], this is why you obtain an error about 3D/4D shapes. You need to reshape your tensor: [None, 12, 12, 64] -> [None, 144, 64]. To do this, you can insert Reshape layer between your last MaxPooling2D and LSTM layers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文