Closed arvoelke closed 4 years ago
If you use sim.save_params
/load_params
then this will work. When using keras_model.save_weights
you're also saving the internal simulation state (which has a minibatch dimension), which is why those parameters don't transfer between models with different minibatch size.
Good to know. For reference the reason [save|load]_weights
is being used as opposed to [save|load]_params
is because I'm using the ModelCheckpoint
callback with save_weights_only=True
. Setting this to False
triggers some issue in the serialization/deserialization logic when trying to load them back in.
Going to use this issue to track the idea of implementing some thin wrapper around ModelCheckpoint
that will call sim.save_params
instead of sim.keras_model.save_weights
.
Note to future self. An easier fix might be to store simulator state as a simple tf.Variable
(not added through layer.add_weights
). Then Keras wouldn't track it, and sim.keras_model.save_weights
would produce the same behaviour as sim.save_params
(only saving the trainable parameters of the model).
Related to #132.
Minimal reproducer:
Stack trace:
Expected behaviour: Expected this to be okay, as one might want to change the minibatch size from one run to another (e.g., to work around #132 or #121, or to experiment with different batch sizes) while reusing the same model parameters from a previous run.