adapt-python/adapt

How to save model weights after transfer learning

9527-ly opened this issue · 3 comments

How to save the adjusted model after updating the model weight using domain adaptation or transfer learning? For example, I used the TrAdaBoostR2 method. But when I save the model, whether it is model.save or model.save_ weights have no effect.

Hi @9527-ly,
Thank you for your interest in the adapt library.
TrAdaBoostR2 has no save_weights method. However, you may succeed to pickle the object using joblib:

import joblib

joblib.dump(model, "model.pkl")

loaded_model = joblib.load("model.pkl")

If for some reason it doesn't work, you can always save the weights of every estimator in TrAdaBoostR2:

for i in range(model.n_estimators):
    model.estimators_[i].save_weights("model_%i.hdf5"%i)

Please, do not hesitate if you have further questions.

Best,

Hi @antoinedemathelin, thank you for your answer. I have succeeded to pickle the object using joblib.