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 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站