mathLab / PINA

Physics-Informed Neural networks for Advanced modeling
https://mathlab.github.io/PINA/
MIT License
387 stars 65 forks source link

Saving the trained model and used it in other code #241

Closed karfungc closed 8 months ago

karfungc commented 8 months ago

Is there a method to saving the trained PINN model and call it in another code?

dario-coscia commented 8 months ago

Hello👋🏼 There are methods to save a trained model, solver and trainer. By default Pytorch Lightining creates loggers and checkpoints during training saving:

more information here

By default all checkpoints for each run are saved in the current directory under a directory called lightning_logs. If you want to specify where to save the checkpoints just passed the argument default_root_dir to the Trainer before training. Then for restoring you can either restore training: trainer.train(ckpt_path=[YOUR PATH]); or you can restore a trained solver: trained_solver = SOLVER.load_from_checkpoint( [YOUR PATH], problem, model) where SOLVER is the class object representing any pina solver (e.g. PINN, SupervisedSolver, …)

For a working example look at the test_train_restore and test_train_load method in the tests folder .

Let me know how it goes and if it was helpful for you😃. If you like the package leave us a star ⭐️ which helps us grow the community!

karfungc commented 8 months ago

Thank you! Will check it