I'm trying to create an ensemble model that gets the same input as the sub models.
models = list()
nb_models = 3
#load all sub models
for i in range(nb_models):
model_tmp = load_model("lstm_model"+str(i+1)+".h5")
model_tmp.name = "model_"+str(i+1)
models.append(model_tmp)
def create_ensemble(models,model_input):
# take-in all outputs fro all models
outModels = [model(model_input) for model in models]
# calculate average of all results
outAvg = layers.average(outModels)
# merge into one model
modelMerge = Model(inputs=model_input,outputs=outAvg,name='ensemble')
return modelMerge
model_input = Input(shape=models[0].input_shape[1:])
modelEns = create_ensemble(models,model_input)
When I load my ensemble model and feed it same data as I did for seperate sub models, I got the following error.
You must feed a value for placeholder tensor 'lstm_2_input' with dtype float and shape [1,1,1] [[{{node lstm_2_input}}]]
For the three sub models they have:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (1, 1) 12
_________________________________________________________________
dense_1 (Dense) (1, 1) 2
=================================================================
and for the ensemble model:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 1, 1) 0
__________________________________________________________________________________________________
model_1 (Sequential) multiple 14 input_1[0][0]
__________________________________________________________________________________________________
model_2 (Sequential) multiple 14 input_1[0][0]
__________________________________________________________________________________________________
model_3 (Sequential) multiple 14 input_1[0][0]
__________________________________________________________________________________________________
average_1 (Average) (None, 1) 0 model_1[1][0]
model_2[1][0]
model_3[1][0]
==================================================================================================
test_reshaped.shape()
(28, 1, 1)