也有类似的问题,但它们要么过时,要么不适用于我的情况。
这是我的代码:
left = Sequential()
left.add(LSTM(units=24,input_shape=(left_X.shape[1], left_X.shape[2])))
left.add(Dense(1))
right = Sequential()
right.add(LSTM(units=24,input_shape=(right_X.shape[1], right_X.shape[2])))
right.add(Dense(1))
model = Sequential()
model.add(Concatenate([left,right]))
model.add(Flatten())
model.add(Dense(1, activation='linear'))
model.compile(loss='mse',
optimizer='adam',
metrics=['mae'])
history = model.fit([left_X, right_X], train_y,
epochs=40,
validation_split=0.2,
verbose=1)
它为Assertion Error
引发fit
585 # since `Sequential` depends on `Model`.
586 if isinstance(inputs, list):
--> 587 assert len(inputs) == 1
588 inputs = inputs[0]
589 self.build(input_shape=(None,) + inputs.shape[1:])
答案 0 :(得分:0)
我使用以下代码解决了该问题,该代码使用Keras功能API:
inp1 = Input(shape=(train_X_1.shape[1], train_X_1.shape[2]))
inp2 = Input(shape=(train_X_2.shape[1], train_X_2.shape[2]))
inp3 = Input(shape=(train_X_3.shape[1], train_X_3.shape[2]))
x = SimpleRNN(10)(inp1)
x = Dense(1)(x)
y = LSTM(10)(inp2)
y = Dense(1)(y)
z = LSTM(10)(inp3)
z = Dense(1)(z)
w = concatenate([x, y, z])
# u = Dense(3)(w)
out = Dense(1, activation='linear')(w)
model = Model(inputs=[inp1, inp2, inp3], outputs=out)
model.compile(loss='logcosh',
optimizer='adam',
metrics=['mae'])
history = model.fit([train_X_1, train_X_2, train_X_3], train_y,
epochs=20,
validation_split=0.1,
verbose=1)