Search code examples
kerasdeep-learningconv-neural-networkkeras-layer

Average weights from two .h5 folders in keras


I have trained two models on different datasets and saved weights of each model as ModelA.h5 and ModelB.h5 I want to average these weights and create a new folder called ModelC.h5 and load it on the same model architechture. How do I do it?


Solution

  • Model trained on different datasets can't just be added like this. It looks something like this. Let's say like this, train one person to classify 1000 images into 5 classes, then, train another person to classify another 1000 images into same 5 classes. Now, you want to combine them into one.

    Rather, what you can do is take ensemble of both the networks. There are multiple ways to ensemble the predictions of both models using Max Voting, Averaging or Weighted Average, Bagging and Boosting, etc. Ensemble helps to boost the weak classifiers into one strong classifier.

    You can refer to this link to read more about different types of ensemble: Link