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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料