预测中的错误-Keras Functional API

时间:2018-08-09 16:08:17

标签: python neural-network keras

我已经训练了这个模型:

from keras.layers import concatenate
from keras.layers import Input, Dense, Masking
from keras.models import Model

x_in = Input(shape=(5,), name='x_in')

s_in = Input(shape=(18,), name='s_in')

s_masked = Masking(0.0)(s_in)

z = concatenate([x_in,s_masked])

dense_1 = Dense(40, kernel_initializer='normal', activation='relu', name='dense_1')(z)
dense_2 = Dense(40, kernel_initializer='normal', activation='relu', name='dense_2')(dense_1)

output = Dense(1, kernel_initializer='normal', name = 'output')(dense_2)

model = Model(inputs=[x_in,s_in], outputs=output)

model.compile(optimizer='adam', loss={'output':'mean_squared_error'})
model.fit({'x_in': x_training,'s_in':s_training},{'output':y_training},batch_size=30, epochs=10, validation_split=0.3, shuffle=True, callbacks=[plot_losses])

我现在要预测。但是由于我有多个输入,因此我不知道如何使用model.predict()

当我尝试:

predictions = model.predict(x_testing, s_testing)
print predictions

我收到此错误:

  

该模型需要2个输入数组,但只接收一个数组。发现:   形状为(1710,5)的数组

我不明白,因为我给了两个数组x_testings_testing

1 个答案:

答案 0 :(得分:0)

您应该像建立模型(inputs=[x_in,s_in])一样将输入作为连接数组来输入:

predictions = model.predict([x_testing, s_testing])