Hi,
I’m trying to apply what I’ve learned so far to a new problem: implementing a subclassed model where I override certain methods, such as train_step
. To save the model, I’m using the ModelCheckpoint
callback.
My goal is to save not only the model’s architecture and weights but also the custom methods and training configuration, allowing me to resume training from the exact state where it was left off. According to the Keras/TensorFlow documentation, the HDF5
format appears to save only the weights of a subclassed model. Therefore, I attempted to use the SavedModel
and Keras
formats, but after loading the model, the training configuration and custom methods were missing.
Am I overlooking something?
Here’s a code snippet to reproduce the issue: Google Colab
did you check you gan.compile output before saved the mode.
The warning states model.compile wasn’t built, so it is stating you saving that model didn’t include the optimiser and loss even if you had added loss and optimizer in your code block.
Also runtimeerror usually happens when a code cells has run down and still not every part of the code was successfully run down, throwing runtime error.
As far I remember you can save the model, to save the custom weight what step you took is unclear with the codes.
You are using GAN model, so I am assuming you have good gpu or cpu configuration to run multiple tasks at the same time.
Hi @Deepti_Prasad
Thanks for your replay.
I inspected the compilation, before saving and after loading the model:
As you can see, the optimizer, loss, and metrics are available in both cases, so I still don’t understand why I’m unable to call loaded_model.fit()
.
To clarify, I’m saving the model using the ModelCheckpoint
callback, and my goal is to save not only the weights but also: the architecture, training configuration, and custom methods (such as the overridden train_step
).