Project-MONAI / research-contributions

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

question about test.py #46

Closed 1640477469 closed 2 years ago

1640477469 commented 2 years ago

when i use UNETR_model_best_acc.pt,i can get the result,but when i use my own model.pt,there have RuntimeError: PytorchStreamReader failed locating file constants.pkl: file not found.how can i solve it?

ahatamiz commented 2 years ago

Hi @1640477469

It is most likely a mismatch between your Pytorch/MONAI version and specified dependencies in this repository.

Thanks

hanoonaR commented 2 years ago

Hi @1640477469,

I faced the same problem with UNETR models trained using the repository. Did you find any solution?

Thank you.

Jamshidhsp commented 2 years ago

Same issue with me, I am not able to load my own trained model. Could somebody work it out please?

hanoonaR commented 2 years ago

@Jamshidhsp,

I solved it by modifying the line in UNETR/BTCV/trainer.py that saves the model as,

torch.save(model.state_dict(), filename). Provide the filename as model.pth instead of model.pt.

Thank you.

Jamshidhsp commented 2 years ago

@hanoonaR Thank you very much. I did it and now, I am facing the error: RuntimeError: PytorchStreamReader failed locating file constants.pkl: file not found

Could you manage it? Thanks

hanoonaR commented 2 years ago

@Jamshidhsp, Yes I faced the same issue and had to retrain the model and save it in the above mentioned way, in .pth form. The issue was then resolved. Thank you.

Jamshidhsp commented 2 years ago

@hanoonaR Thank you again. I am gonna retrain again!

Jamshidhsp commented 2 years ago

@hanoonaR Thank you very much for your help. Actually I tried to get over it. I used the same version of pytorch and monai, changed model from .pt to .pth. But at the end, I face the error again. I am wondering the problem arises from python version or protobuf version. Could you please check the version of protobuf/python you used? I really appreciate it. Thanks

hanoonaR commented 2 years ago

HI @Jamshidhsp ,

Sure. Please find the environment details: python: 3.8.13 protobuf: 3.19.4 torch: 1.9.1+cu111 monai: 0.7.0 nibabel: 3.1.1

PS: Please note that the command to save model is modified from torch.save(save_dict, filename) to torch.save(model.state_dict(), filename).

Hope it helps. Thank you.

Jamshidhsp commented 2 years ago

@hanoonaR Thank you for the details and your help. It didn't work, but very useful. I will try finding it out.

Jamshidhsp commented 2 years ago

@hanoonaR I saw you edited the message on saving the model. It works now! You helped a lot. I really appreciate it!