model-zoo icon indicating copy to clipboard operation
model-zoo copied to clipboard

Add TorchScript model (model.ts) for Swin UNETR segmentation

Open cvbourne opened this issue 8 months ago • 2 comments

Fixes # .

Description

This PR adds a traced TorchScript model (model.ts) to address issue #511 in the monai-deploy-app-sdk repository, where the ai_unetr_seg_app example cannot run due to a missing traced model. The original error in the app was: monai.deploy.exceptions.ItemNotExistsError: A predictor of the model is not set. The example app expects a TorchScript model, but the current model provided in the Model Zoo (model_swin_unetr_btcv_segmentation_v1.pt) is a standard PyTorch model, not a TorchScript format.

Solution I've created a traced version of the Swin UNETR BTCV segmentation model by:

Loading the original model's state dictionary Creating a new SwinUNETR instance with the correct parameters Tracing the model using torch.jit.trace with appropriate input dimensions Preparing the necessary model file structure according to Model Zoo guidelines

Status

Ready

Please ensure all the checkboxes:

  • [x] Codeformat tests passed locally by running ./runtests.sh --codeformat.
  • [ ] In-line docstrings updated.
  • [ ] Update version and changelog in metadata.json if changing an existing bundle.
  • [ ] Please ensure the naming rules in config files meet our requirements (please refer to: CONTRIBUTING.md).
  • [ ] Ensure versions of packages such as monai, pytorch and numpy are correct in metadata.json.
  • [ ] Descriptions should be consistent with the content, such as eval_metrics of the provided weights and TorchScript modules.
  • [x] Files larger than 25MB are excluded and replaced by providing download links in large_file.yml.
  • [ ] Avoid using path that contains personal information within config files (such as use /home/your_name/ for "bundle_root").

cvbourne avatar Apr 25 '25 18:04 cvbourne

@MMelQin In case you'd like to review as well.

cvbourne avatar Apr 25 '25 20:04 cvbourne

Hi @cvbourne , thanks for the PR, could you also update the change log and version in the modified bundle's metadata.json? Thanks!

yiheng-wang-nv avatar Apr 29 '25 07:04 yiheng-wang-nv