【问题标题】:Improperly concatenating LSTM layers in Python keras在 Python keras 中不正确地连接 LSTM 层
【发布时间】:2021-01-08 19:38:11
【问题描述】:

我想将两个具有不同时间分辨率的数据集输入到同一个 LSTM 模型中。我遇到了连接过程的问题,即使我使用了一个简单的数据集,并且相信我错过了一些我看不到的简单的东西。让我们以下面的简单示例为例,它是我正在尝试的方法的简化版本:

import numpy as np
from keras import layers

train_x1 = np.random.randint(0,100,size=(10,10,10)) # 10 samples, 10 time-steps, 10 variables
train_x2 = np.random.randint(0,100,size=(10,30,6)) # 10 samples, 30 time-steps, 6 variables

inp1 = layers.Input(shape=(train_x1.shape[1], train_x1.shape[2]))
inp2 = layers.Input(shape=(train_x2.shape[1], train_x2.shape[2]))

x = layers.LSTM(10)(inp1)
y = layers.LSTM(10)(inp2)

x = layers.Dense(1)(x)
y = layers.Dense(1)(y)

z = np.concatenate([x,y])

但我得到一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: zero-dimensional arrays cannot be concatenated

我很困惑这个例子中的错误来自哪里?

【问题讨论】:

  • 使用 keras 层的连接层...不是 np.concatenate

标签: numpy keras concatenation concat


【解决方案1】:

xy 是 keras 张量对象,在它们上使用 np.concatenate 是没有意义的。可能你想试​​试keras.layers.Concatenate()([x,y])

【讨论】:

    猜你喜欢
    • 2019-08-21
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 2021-06-07
    • 2019-01-04
    • 2020-09-04
    相关资源
    最近更新 更多