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

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

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的东西,你这段代码完全都是问题啊

你需要安装sse版的tensorflow,或者找一台Core i5/i7 4系列以上的CPU的计算机(比如i7 4770K i7 7700K等)
你的CPU太老,不支持AVX2指令。

另外nput 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4
你的lstm输入层应该是3维度的,是不是你把y维度也放进去了