在 Keras 中使用 TimeDistributed 和循环层

埃里克夫

我想在每个批次的几个不同序列上运行 LSTM,然后加入最后的输出。这是我一直在尝试的:

from keras.layers import Dense, Input, LSTM, Embedding, TimeDistributed

num_sentences = 4
num_features = 3
num_time_steps = 5

inputs = Input([num_sentences, num_time_steps])
emb_layer = Embedding(10, num_features)
embedded = emb_layer(inputs)
lstm_layer = LSTM(4)

shape = [num_sentences, num_time_steps, num_features]
lstm_outputs = TimeDistributed(lstm_layer, input_shape=shape)(embedded)

这给了我以下错误:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    lstm_outputs = TimeDistributed(lstm_layer, input_shape=shape)(embedded)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 546, in __call__
    self.build(input_shapes[0])
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/layers/wrappers.py", line 94, in build
    self.layer.build(child_input_shape)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/layers/recurrent.py", line 702, in build
    self.input_dim = input_shape[2]
IndexError: tuple index out of range

我尝试省略 中的input_shape参数TimeDistributed,但它没有改变任何东西。

埃里克夫

在尝试了 michetonu 的回答并出现了同样的错误后,我意识到我的 keras 版本可能已经过时了。实际上,正在运行 keras 1.2,并且代码在 2.0 上运行良好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在TimeDistributed层内正确使用keras SpatialDropout2D-CNN LSTM网络

来自分类常见问题

在Keras中,TimeDistributed层的作用是什么?

来自分类Dev

如何不在 Keras 中输出带有“TimeDistributed”层的序列?

来自分类Dev

为什么 Keras 序列到序列教程没有提到 TimeDistributed 层包装器?

来自分类Dev

如何使用TimeDistributed层来预测动态长度序列?PYTHON 3

来自分类Dev

如何使用for循环创建Keras多LSTM层?

来自分类Dev

在 Keras 中使用连接层进行小批量学习?

来自分类Dev

在Keras(深度学习库)中,RepeatVector + TimeDistributed =错误?

来自分类Dev

如何在 CNN 块上应用 TimeDistributed 层?

来自分类Dev

如何在Tensorflow 2.x Keras自定义层中使用多个输入?

来自分类Dev

在 Keras 中使用 Lambda 层时出现符号张量值错误

来自分类Dev

在 Keras 中将 TimeDistributed 应用于 InceptionResnetV2 时出错

来自分类Dev

使用keras python输出卷积层

来自分类Dev

keras 双向层使用 4 维数据

来自分类Dev

使用 keras 在各个层上应用卷积

来自分类Dev

在循环中使用Keras时如何防止内存使用量激增

来自分类Dev

在循环中使用Keras时如何防止内存使用量激增

来自分类Dev

如何在tf.keras中使输入层显式

来自分类Dev

如何在自定义训练循环中使用tf.keras.layers.BatchNormalization()?

来自分类Dev

张量的矢量化运算,而不是在keras自定义损失函数中使用for循环

来自分类Dev

GRU (return_sequences=True) 层之后的 TimeDistributed Dense Layer 导致维度错误

来自分类Dev

在 r 中使用 keras 将 acc 和 val_acc 归零

来自分类Dev

使用keras自定义层时生成错误

来自分类Dev

如何使用KERAS获得DNN的最后一层的值?

来自分类Dev

使用 keras 在 CNN 中创建一个特殊层

来自分类Dev

在Keras.model中使用tf.keras.layers

来自分类Dev

在Keras模型中使用Tf-Idf

来自分类Dev

如何在keras图层中使用SVD?

来自分类Dev

如何在 Keras 中使用中级微调?

Related 相关文章

  1. 1

    在TimeDistributed层内正确使用keras SpatialDropout2D-CNN LSTM网络

  2. 2

    在Keras中,TimeDistributed层的作用是什么?

  3. 3

    如何不在 Keras 中输出带有“TimeDistributed”层的序列?

  4. 4

    为什么 Keras 序列到序列教程没有提到 TimeDistributed 层包装器?

  5. 5

    如何使用TimeDistributed层来预测动态长度序列?PYTHON 3

  6. 6

    如何使用for循环创建Keras多LSTM层?

  7. 7

    在 Keras 中使用连接层进行小批量学习?

  8. 8

    在Keras(深度学习库)中,RepeatVector + TimeDistributed =错误?

  9. 9

    如何在 CNN 块上应用 TimeDistributed 层?

  10. 10

    如何在Tensorflow 2.x Keras自定义层中使用多个输入?

  11. 11

    在 Keras 中使用 Lambda 层时出现符号张量值错误

  12. 12

    在 Keras 中将 TimeDistributed 应用于 InceptionResnetV2 时出错

  13. 13

    使用keras python输出卷积层

  14. 14

    keras 双向层使用 4 维数据

  15. 15

    使用 keras 在各个层上应用卷积

  16. 16

    在循环中使用Keras时如何防止内存使用量激增

  17. 17

    在循环中使用Keras时如何防止内存使用量激增

  18. 18

    如何在tf.keras中使输入层显式

  19. 19

    如何在自定义训练循环中使用tf.keras.layers.BatchNormalization()?

  20. 20

    张量的矢量化运算,而不是在keras自定义损失函数中使用for循环

  21. 21

    GRU (return_sequences=True) 层之后的 TimeDistributed Dense Layer 导致维度错误

  22. 22

    在 r 中使用 keras 将 acc 和 val_acc 归零

  23. 23

    使用keras自定义层时生成错误

  24. 24

    如何使用KERAS获得DNN的最后一层的值?

  25. 25

    使用 keras 在 CNN 中创建一个特殊层

  26. 26

    在Keras.model中使用tf.keras.layers

  27. 27

    在Keras模型中使用Tf-Idf

  28. 28

    如何在keras图层中使用SVD?

  29. 29

    如何在 Keras 中使用中级微调?

热门标签

归档