How to correctly load a trained ModelComparisonApproximator model?

Hi everyone,

I am starting to learn more about using Bayesflow, but I don’t have much experience with keras before, so this might be a trivial question. After training my network using a ModelComparisonApproximator I saved it using approximator.save("..\..\Results\model_v1.keras") and then later loaded it again with keras.saving.load_model("..\Results\model_v1.keras").

However, whereas the confusion matrix on simulated data using this code pred_models = approximator.predict(conditions= simulator.sample(10000)) directly after training looked like this

it looks like this when I reload the model and sample from the simulator again:

So what would be the best or correct way to save a model for later use?

Best,
David

Hi David, which version of bayeaflow do you have installed? Does the problem still persist when you reinstall from dev?

Hey Stefan!

I am currently using 2.0.3, I will try it with the dev version and give you an update.

I reinstalled BayesFlow from dev using pip install git+https://github.com/bayesflow-org/bayesflow.git@dev. I tried again, but the results where the same, but I also got this warning now: UserWarning: Skipping variable loading for optimizer 'adam', because it has 1 variables whereas the saved optimizer has 169 variables.

Hi David,

thank you for reporting this. Could you please create an issue on the repo, including a minimal reproducible code sample? We will work on fixing the issue ASAP.

Thank you.
Lars

Hey, I created an issue on the repo, thank you for looking into this.

1 Like