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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?