Project-MONAI / research-contributions

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

Evaluation of trained UNETR models with test.py #77

Closed hanoonaR closed 2 years ago

hanoonaR commented 2 years ago

Hi,

I am facing an issue in evaluating the UNETR models trained with the repository. I saw there was a previous issue that raised the same problem: https://github.com/Project-MONAI/research-contributions/issues/46.

The models trained with the code base could not be evaluated with test.py because torch.jit.load(pretrained_pth) throws the error "RuntimeError: PytorchStreamReader failed locating file constants.pkl: file not found". image

The validation was performed as expected in the trainer.py. However the model saved using the function https://github.com/Project-MONAI/research-contributions/blob/2f881c602863c9556dcce9847ffecc4cac919eaf/UNETR/BTCV/trainer.py#L137 cannot be loaded using torch.jit.load(pretrained_pth). How should the model be correctly saved?

The torch and monai versions are exactly same as specified in the installation requirements. image

Kindly suggest a solution. Thank you.

tangy5 commented 2 years ago

hi @hanoonaR , thanks for the comment. In the save_checkpoint function, the models are saved as a dictionary. save_dict = {"epoch": epoch, "best_acc": best_acc, "state_dict": state_dict} The "state_dict" should be the model weights. Not sure whether is the key-value problem for Torchscript conversion. Will continue verify this. Thanks.