Project-MONAI / research-contributions

Implementations of recent research prototypes/demonstrations using MONAI.
https://monai.io/
Apache License 2.0
967 stars 322 forks source link

Training model cannot load properly #322

Open SiruLiu645 opened 9 months ago

SiruLiu645 commented 9 months ago

I use a heart CT dataset to train this model,and I save this model when loss decrease to 0.7. However, I cannot load this pretrained model when I run test.py. image Then I changed the code "model_dict = torch.load(pretrained_pth)" to "model_dict = torch.load(pretrained_pth)["state_dict"]", it came to another problem: image

taishanglaojunya commented 4 weeks ago

yes, I have the same problem!!! Do you have a solution now?

ericspod commented 4 weeks ago

Hi both, sorry for the lateness of reply. I think the latter case when you're loading from the "state_dict" key is the correct thing to do, however the model that you've instantiated has different constructor arguments from the model that these weights were saved from. You'll need to figure out what the parameters were exactly and be sure your class is instantiated correctly, if your weights are very old it's possible the class definition has changed and you may have to get the old version of the code from a previous MONAI release on Github and copy that into your project.

taishanglaojunya commented 1 day ago

谢谢你的提示!

Eric Kerfoot @.***> 于2024年6月10日周一 19:42写道:

Hi both, sorry for the lateness of reply. I think the latter case when you're loading from the "state_dict" key is the correct thing to do, however the model that you've instantiated has different constructor arguments from the model that these weights were saved from. You'll need to figure out what the parameters were exactly and be sure your class is instantiated correctly, if your weights are very old it's possible the class definition has changed and you may have to get the old version of the code from a previous MONAI release on Github and copy that into your project.

— Reply to this email directly, view it on GitHub https://github.com/Project-MONAI/research-contributions/issues/322#issuecomment-2158118277, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDN4R34OE7NQB46IDWASUTTZGWGMFAVCNFSM6AAAAABJBXKC5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJYGEYTQMRXG4 . You are receiving this because you commented.Message ID: @.***>