maziarraissi / PINNs

Physics Informed Deep Learning: Data-driven Solutions and Discovery of Nonlinear Partial Differential Equations
https://maziarraissi.github.io/PINNs
MIT License
3.98k stars 1.29k forks source link

save weight of the model #35

Open Hochinghao opened 3 years ago

Hochinghao commented 3 years ago

is there anyway to save the trained model?

sajed-zarrinpour commented 3 years ago

I think this article will help you out. https://www.tensorflow.org/tutorials/keras/save_and_load

Hochinghao commented 3 years ago

but it seens work for keras model but it is tensorflow model .

sajed-zarrinpour commented 3 years ago

I believe you can use the principle here. you can use a costume callback for the purpose as well. try tracing these variables: self.weights self.biases I think it will help.

Mohamadrezash204 commented 8 months ago

is there anyway to save the trained model?

you can add this to model:

def save_model(self):
    saver = tf.train.Saver()
    save_path = "meltpool_model.ckpt"
    saver.save(self.sess, save_path)
    print(f"Model saved at {save_path}")

def load_model(self):
    saver = tf.train.Saver()
    save_path = "meltpool_model.ckpt"
    saver.restore(self.sess, save_path)
    print(f"Model loaded from {save_path}")    

To save the model you should call save_model after training. and when you want to use the saved model before the train call the load_model.