Closed eahn7 closed 3 years ago
@eahn7 check point only saves the weights. You can save the full model by calling model.save_model after you have gotten a final model version. The json file stores the configuration and is the same for a given model training. The way I usually do is training the model to convergence first, then loading the best weight, and saving this model at last.
@chc273 I see. Thank you for your quick response.
Hi,
I am trying to save a MEGNet model via
train
method (defined inGraphModel
class) as illustrated in the sample usage codes. If I understand correctly, thetrain
method calls customModelCheckpointMAE
then saves Keras hdf5 files in thecallback
directory by default.I can see hdf5 files are generated as the training proceeds, but I do not see any json files associated with hdf5 files are constructed accordingly. It seems I do need both hdf5 and json files to load a trained MEGNet model via
from_file
method as per the sample notebook insave_and_load_model.ipynb
.I debugged some codes, and it seems that
ModelCheckpointMAE
actually saves the model through standardtf.keras.Model.save()
. https://github.com/materialsvirtuallab/megnet/blob/6d5766d4134c04f9b1c41de0dab6a3c6234df7cb/megnet/callbacks.py#L136Aren't we suppose to use
save_model
method defined inGraphModel
class to save a model in json and hdf5 format? I have been trying to workaround the issue by changingself.model.save()
toself.model.save_model()
, but got an AttributeError: 'Functional' object has no attribute 'save_model'.I think tf.keras.callbacks can only access to the Functional type, not the encapsulated models like MEGNet. Can someone help me with saving and loading a MEGNet model during training? Thank you.