Bach_Orc 2019-06-19 11:22 采纳率: 100%
浏览 829
已采纳

LSTM的格式 与卷积 。。。。。。。。。。。

inputs = Input(shape=(28, 140, 1))  
s_model = Sequential()
s_model.add(LSTM(11, input_shape=(28, 140, 1)))
s_model.add(LSTM(11, dropout=0.2, recurrent_dropout=0.2))
x = Conv2D(5, (3, 3), activation='relu')(inputs)
s_model.add(x=Conv2D(5, (3, 3), activation='relu')(x))
s_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
s_model.fit(x_train, y_train, batch_size=32, epochs=1)

predict_test = s_model.predict(x_test)
predict_list = []

错误:

Using TensorFlow backend.
WARNING:tensorflow:From D:\Python\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
2019-06-18 23:20:57.371797: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
  File "C:/Users/13544/Documents/yhz-internship/work.py", line 86, in <module>
    s_model.add(LSTM(11, input_shape=(28, 140, 1)))
  File "D:\Python\lib\site-packages\keras\engine\sequential.py", line 165, in add
    layer(x)
  File "D:\Python\lib\site-packages\keras\layers\recurrent.py", line 532, in __call__
    return super(RNN, self).__call__(inputs, **kwargs)
  File "D:\Python\lib\site-packages\keras\engine\base_layer.py", line 414, in __call__
    self.assert_input_compatibility(inputs)
  File "D:\Python\lib\site-packages\keras\engine\base_layer.py", line 311, in assert_input_compatibility
    str(K.ndim(x)))
ValueError: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4
4

  • 写回答

2条回答 默认 最新

  • 阿夏z 2019-06-19 12:06
    关注

    inputs = Input(shape=(28, 140, 1))

    s_model = Sequential()
    s_model.add(LSTM(140))
    s_model.add(LSTM(140, dropout=0.2, recurrent_dropout=0.2))
    第二个维度140要和lstm cell的值一致
    你应该取学习一下基础的lstm网络和cnn的东西,你这段代码完全都是问题啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么