# How to combine two Deep learning model weights into one

Suppose I have these two models (model1 and model2) trained from same structured data, but different datasets:

# create and fit the LSTM network on dataset1
model = Sequential()
model.compile(loss='mean_squared_error', optimizer=optimizer)
model.summary()
model1 = model.fit(trainX, trainY, epochs=100, batch_size=64, verbose=2)
model1.save_weights("Model1.h5")

# create and fit the LSTM network on dataset2
model = Sequential()
model.compile(loss='mean_squared_error', optimizer=optimizer)
model.summary()
model2 = model.fit(trainX, trainY, epochs=100, batch_size=64, verbose=2)
model2.save_weights("Model2.h5")


How do I combine Model1.h5 and Model2.h5 to make suppose Model3.h5 which has all the attributes of Model1.h5 and Model2.h5 ?

Any help will be highly appreciated.

Thanks,

• How different are the datasets ? Aug 23 '18 at 9:47
• @alexandre_d - just new input, other than that the structure is the same, as in same column names, same number of columns.
– Jazz
Aug 23 '18 at 9:48
• Does it represent the same distribution of data/tasks ? Aug 23 '18 at 9:51
• @alexandre_d- absolutely.
– Jazz
Aug 23 '18 at 9:51
• Just make predictions using both models and take the mean :-) Aug 23 '18 at 11:20