monet-bundle


Namemonet-bundle JSON
Version 1.0rc0 PyPI version JSON
download
home_pagehttps://github.com/SimoneBendazzoli93/MONet-Bundle.git
SummaryA Python package providing the MONet Bundle for nnUNet, extending it with MONAI functionalities and access to the MAIA Segmentation Portal.
upload_time2025-07-12 14:43:50
maintainerNone
docs_urlNone
authorBendazzoli Simone
requires_python>=3.10
licenseGPLv3
keywords monai model inference pytorch monet bundle maia
VCS
bugtrack_url
requirements None None None nvflare PyJWT python-on-whales
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MONet Bundle

[![Build](https://github.com/SimoneBendazzoli93/MONet-Bundle/actions/workflows/build.yaml/badge.svg)](https://github.com/SimoneBendazzoli93/MONet-Bundle/actions/workflows/build.yaml)

[![Documentation Status](https://readthedocs.org/projects/monet-bundle/badge/?version=latest)](https://monet-bundle.readthedocs.io/en/latest/?badge=latest)
![Version](https://img.shields.io/badge/MONet-v1.0-blue)
[![License](https://img.shields.io/badge/license-GPL%203.0-green.svg)](https://opensource.org/licenses/GPL-3.0)
![Python](https://img.shields.io/badge/python-3.10+-orange)


![GitHub Release Date - Published_At](https://img.shields.io/github/release-date/SimoneBendazzoli93/MONet-Bundle?logo=github)
![GitHub contributors](https://img.shields.io/github/contributors/SimoneBendazzoli93/MONet-Bundle?logo=github)
![GitHub top language](https://img.shields.io/github/languages/top/SimoneBendazzoli93/MONet-Bundle?logo=github)
![GitHub language count](https://img.shields.io/github/languages/count/SimoneBendazzoli93/MONet-Bundle?logo=github)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/SimoneBendazzoli93/MONet-Bundle/publish_release.yaml?logo=github)
![GitHub all releases](https://img.shields.io/github/downloads/SimoneBendazzoli93/MONet-Bundle/total?logo=github)
![PyPI - Downloads](https://img.shields.io/pypi/dm/monet-bundle?logo=pypi)
![GitHub](https://img.shields.io/github/license/SimoneBendazzoli93/MONet-Bundle?logo=github)
![PyPI - License](https://img.shields.io/pypi/l/monet-bundle?logo=pypi)


![GitHub repo size](https://img.shields.io/github/repo-size/SimoneBendazzoli93/MONet-Bundle?logo=github)
![GitHub release (with filter)](https://img.shields.io/github/v/release/SimoneBendazzoli93/MONet-Bundle?logo=github)
![PyPI](https://img.shields.io/pypi/v/monet-bundle?logo=pypi)

This repository contains the implementation of the MONet Bundle, with some instructions on how to use it and how to convert a generic nnUNet model to MONAI Bundle format.

For more details about the MONet Bundle, please refer to the Jupyter notebook [MONet_Bundle.ipynb](./MONet_Bundle.ipynb).


## 2025-06-25 UPDATE: Check out the MONet Bundle for FedBraTS and FedLymphoma!
The MONet Bundle has been used in the Federated Brain Tumor Segmentation [FedBraTS](./Projects/FedBraTS/README.md) and Federated Lymphoma Segmentation [FedLymphoma](./Projects/FedLymphoma/README.md) projects, which are described in the following paper:
- [MONet-FL: Extending nnU-Net with MONAI for Clinical Federated Learning]()


## Download the MONet Bundle
You can download the MONet Bundle from the following link: [MONet Bundle](https://raw.githubusercontent.com/SimoneBendazzoli93/MONet-Bundle/main/MONetBundle.zip)
ALternatively, you can use the following command to download the MONet Bundle:
```bash
wget https://raw.githubusercontent.com/SimoneBendazzoli93/MONet-Bundle/main/MONetBundle.zip
```
or, through the Python Script:
```bash
MONet_fetch_bundle.py --bundle_path <FOLDER_PATH>
``` 

## Convert a trained nnUNet model to MONAI Bundle

To convert a trained nnUNet model to MONAI Bundle format, you can start with exporting a nnUNet trained model  with the `nnUNetv2_export_model_to_zip` command. This command will export the model to a zip file that can be used in the conversion process.
```bash
nnUNetv2_export_model_to_zip -d 009 -o Task09_Spleen.zip -c 3d_fullres -tr nnUNetTrainer -p nnUNetPlans -chk checkpoint_final.pth checkpoint_best.pth --not_strict
```
For testing purposes, you can use the `Task09_Spleen.zip` file provided in this repository: https://github.com/SimoneBendazzoli93/nnUNet-MONAI-Bundle/releases/download/v1.0/Task09_Spleen.zip. This file contains a trained nnUNet model for the Spleen segmentation task, for only the `3d_fullres` configuration and the fold `0`.



Next, you can build the provided Docker image to convert the model to MONAI Bundle format. The Dockerfile is provided in this repository, and you can build the image with the following command:

```bash
docker build -t nnunet-monai-bundle-converter .
```
The converter will first convert the nnUNet model to MONAI Bundle format, and then create the corresponding TorchScript model, which can be used for inference with MONAI Deploy.
For testing purposes, you can use the `Task09_Spleen.zip` file provided in this repository.

To run the conversion, you can use the following command:
```bash
wget https://github.com/SimoneBendazzoli93/MONet-Bundle/releases/download/v1.0/Task09_Spleen.zip
python MONet_run_conversion.py --bundle_path <MONAI_BUNDLE_PATH> --nnunet_model <NNUNET_CHECKPOINT_PATH>.zip
```

## Package the MONet Bundle with MONAI Deploy
To package the MONet Bundle with MONAI Deploy, you can use the `monai-deploy package` command. This command will create a deployable bundle that can be used for inference with MONAI Deploy.

```bash
monai-deploy package examples/apps/spleen_nnunet_seg_app -c examples/apps/spleen_nnunet_seg_app.yaml -t spleen:1.0 --platform x86_64
```

## Run inference with MONAI Deploy

The resulting Docker context can be found in the `deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0` directory. You can use this context to build a Docker image that can be used for inference with MONAI Deploy:
```bash
# Copy the TorchScript model to the Docker context
cp nnUNetBundle/models/fold_0/model.ts deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0/models/model/

docker build deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0 --build-arg UID=1000 --build-arg GID=1000 --build-arg UNAME=holoscan -f deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0/Dockerfile -t spleen-x64-workstation-dgpu-linux-amd64:1.0
```

To test the resulting Docker image, you can run:
```bash
MONet_inference_dicom.py --dicom_study_folder <INPUT_FOLDER> --prediction_output_folder <OUTPUT_DIR> --docker-image maiacloud/spleen-x64-workstation-dgpu-linux-amd64:1.0
```
Specifying the input and output folders, together with the TorchScript model path.
The input folder should contain all the DICOM files of the study you want to process, and the output folder will contain the predictions in DICOM SEG format, and an additional STL file with the 3D mesh of the segmentation.



To create the same Docker image running inference on NIFTI images, you can use the provided `Dockerfile` in the `deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0-nifti` directory. The Dockerfile is already set up to run inference on NIfTI images, and it includes the necessary dependencies.
To test the resulting Docker image, you can run:
```bash
MONet_inference_nifti.py --study_folder <INPUT_FOLDER> --prediction_output_folder <OUTPUT_DIR> --docker-image maiacloud/spleen-x64-workstation-dgpu-linux-amd64:1.0-nifti
```
Specifying the input and output folders, together with the TorchScript model path.
The input folder should contain all the NIfTI files of the study you want to process (one per modality, with the given suffix identifier), and the output folder will contain the predictions in NIfTI format.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SimoneBendazzoli93/MONet-Bundle.git",
    "name": "monet-bundle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "monai, model inference, pytorch, monet bundle, maia",
    "author": "Bendazzoli Simone",
    "author_email": "simben@kth.se",
    "download_url": "https://files.pythonhosted.org/packages/0a/16/af0d7f90d5c934de9b8eac84821bd81b008cbd4778e89555b9044dc10369/monet_bundle-1.0rc0.tar.gz",
    "platform": "OS Independent",
    "description": "# MONet Bundle\n\n[![Build](https://github.com/SimoneBendazzoli93/MONet-Bundle/actions/workflows/build.yaml/badge.svg)](https://github.com/SimoneBendazzoli93/MONet-Bundle/actions/workflows/build.yaml)\n\n[![Documentation Status](https://readthedocs.org/projects/monet-bundle/badge/?version=latest)](https://monet-bundle.readthedocs.io/en/latest/?badge=latest)\n![Version](https://img.shields.io/badge/MONet-v1.0-blue)\n[![License](https://img.shields.io/badge/license-GPL%203.0-green.svg)](https://opensource.org/licenses/GPL-3.0)\n![Python](https://img.shields.io/badge/python-3.10+-orange)\n\n\n![GitHub Release Date - Published_At](https://img.shields.io/github/release-date/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![GitHub contributors](https://img.shields.io/github/contributors/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![GitHub top language](https://img.shields.io/github/languages/top/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![GitHub language count](https://img.shields.io/github/languages/count/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/SimoneBendazzoli93/MONet-Bundle/publish_release.yaml?logo=github)\n![GitHub all releases](https://img.shields.io/github/downloads/SimoneBendazzoli93/MONet-Bundle/total?logo=github)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/monet-bundle?logo=pypi)\n![GitHub](https://img.shields.io/github/license/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![PyPI - License](https://img.shields.io/pypi/l/monet-bundle?logo=pypi)\n\n\n![GitHub repo size](https://img.shields.io/github/repo-size/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![GitHub release (with filter)](https://img.shields.io/github/v/release/SimoneBendazzoli93/MONet-Bundle?logo=github)\n![PyPI](https://img.shields.io/pypi/v/monet-bundle?logo=pypi)\n\nThis repository contains the implementation of the MONet Bundle, with some instructions on how to use it and how to convert a generic nnUNet model to MONAI Bundle format.\n\nFor more details about the MONet Bundle, please refer to the Jupyter notebook [MONet_Bundle.ipynb](./MONet_Bundle.ipynb).\n\n\n## 2025-06-25 UPDATE: Check out the MONet Bundle for FedBraTS and FedLymphoma!\nThe MONet Bundle has been used in the Federated Brain Tumor Segmentation [FedBraTS](./Projects/FedBraTS/README.md) and Federated Lymphoma Segmentation [FedLymphoma](./Projects/FedLymphoma/README.md) projects, which are described in the following paper:\n- [MONet-FL: Extending nnU-Net with MONAI for Clinical Federated Learning]()\n\n\n## Download the MONet Bundle\nYou can download the MONet Bundle from the following link: [MONet Bundle](https://raw.githubusercontent.com/SimoneBendazzoli93/MONet-Bundle/main/MONetBundle.zip)\nALternatively, you can use the following command to download the MONet Bundle:\n```bash\nwget https://raw.githubusercontent.com/SimoneBendazzoli93/MONet-Bundle/main/MONetBundle.zip\n```\nor, through the Python Script:\n```bash\nMONet_fetch_bundle.py --bundle_path <FOLDER_PATH>\n``` \n\n## Convert a trained nnUNet model to MONAI Bundle\n\nTo convert a trained nnUNet model to MONAI Bundle format, you can start with exporting a nnUNet trained model  with the `nnUNetv2_export_model_to_zip` command. This command will export the model to a zip file that can be used in the conversion process.\n```bash\nnnUNetv2_export_model_to_zip -d 009 -o Task09_Spleen.zip -c 3d_fullres -tr nnUNetTrainer -p nnUNetPlans -chk checkpoint_final.pth checkpoint_best.pth --not_strict\n```\nFor testing purposes, you can use the `Task09_Spleen.zip` file provided in this repository: https://github.com/SimoneBendazzoli93/nnUNet-MONAI-Bundle/releases/download/v1.0/Task09_Spleen.zip. This file contains a trained nnUNet model for the Spleen segmentation task, for only the `3d_fullres` configuration and the fold `0`.\n\n\n\nNext, you can build the provided Docker image to convert the model to MONAI Bundle format. The Dockerfile is provided in this repository, and you can build the image with the following command:\n\n```bash\ndocker build -t nnunet-monai-bundle-converter .\n```\nThe converter will first convert the nnUNet model to MONAI Bundle format, and then create the corresponding TorchScript model, which can be used for inference with MONAI Deploy.\nFor testing purposes, you can use the `Task09_Spleen.zip` file provided in this repository.\n\nTo run the conversion, you can use the following command:\n```bash\nwget https://github.com/SimoneBendazzoli93/MONet-Bundle/releases/download/v1.0/Task09_Spleen.zip\npython MONet_run_conversion.py --bundle_path <MONAI_BUNDLE_PATH> --nnunet_model <NNUNET_CHECKPOINT_PATH>.zip\n```\n\n## Package the MONet Bundle with MONAI Deploy\nTo package the MONet Bundle with MONAI Deploy, you can use the `monai-deploy package` command. This command will create a deployable bundle that can be used for inference with MONAI Deploy.\n\n```bash\nmonai-deploy package examples/apps/spleen_nnunet_seg_app -c examples/apps/spleen_nnunet_seg_app.yaml -t spleen:1.0 --platform x86_64\n```\n\n## Run inference with MONAI Deploy\n\nThe resulting Docker context can be found in the `deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0` directory. You can use this context to build a Docker image that can be used for inference with MONAI Deploy:\n```bash\n# Copy the TorchScript model to the Docker context\ncp nnUNetBundle/models/fold_0/model.ts deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0/models/model/\n\ndocker build deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0 --build-arg UID=1000 --build-arg GID=1000 --build-arg UNAME=holoscan -f deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0/Dockerfile -t spleen-x64-workstation-dgpu-linux-amd64:1.0\n```\n\nTo test the resulting Docker image, you can run:\n```bash\nMONet_inference_dicom.py --dicom_study_folder <INPUT_FOLDER> --prediction_output_folder <OUTPUT_DIR> --docker-image maiacloud/spleen-x64-workstation-dgpu-linux-amd64:1.0\n```\nSpecifying the input and output folders, together with the TorchScript model path.\nThe input folder should contain all the DICOM files of the study you want to process, and the output folder will contain the predictions in DICOM SEG format, and an additional STL file with the 3D mesh of the segmentation.\n\n\n\nTo create the same Docker image running inference on NIFTI images, you can use the provided `Dockerfile` in the `deploy/spleen-x64-workstation-dgpu-linux-amd64:1.0-nifti` directory. The Dockerfile is already set up to run inference on NIfTI images, and it includes the necessary dependencies.\nTo test the resulting Docker image, you can run:\n```bash\nMONet_inference_nifti.py --study_folder <INPUT_FOLDER> --prediction_output_folder <OUTPUT_DIR> --docker-image maiacloud/spleen-x64-workstation-dgpu-linux-amd64:1.0-nifti\n```\nSpecifying the input and output folders, together with the TorchScript model path.\nThe input folder should contain all the NIfTI files of the study you want to process (one per modality, with the given suffix identifier), and the output folder will contain the predictions in NIfTI format.\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "A Python package providing the MONet Bundle for nnUNet, extending it with MONAI functionalities and access to the MAIA Segmentation Portal.",
    "version": "1.0rc0",
    "project_urls": {
        "Bug Tracker": "https://github.com/SimoneBendazzoli93/MONet-Bundle/issues",
        "Documentation": "https://monet-bundle.readthedocs.io",
        "Homepage": "https://github.com/SimoneBendazzoli93/MONet-Bundle.git",
        "Source Code": "https://github.com/SimoneBendazzoli93/MONet-Bundle"
    },
    "split_keywords": [
        "monai",
        " model inference",
        " pytorch",
        " monet bundle",
        " maia"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c0802c80ab13d01b535c3f0ffafa9d020971e807c8b11bf8224a50c9628b28f6",
                "md5": "9c93f4cf02fe7f6192da03dc979e480a",
                "sha256": "2ddc1f316f27852bf8eb1527f63cee4c50fb1811f1ae34f326eb9e1938569627"
            },
            "downloads": -1,
            "filename": "monet_bundle-1.0rc0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c93f4cf02fe7f6192da03dc979e480a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 31169,
            "upload_time": "2025-07-12T14:43:49",
            "upload_time_iso_8601": "2025-07-12T14:43:49.821584Z",
            "url": "https://files.pythonhosted.org/packages/c0/80/2c80ab13d01b535c3f0ffafa9d020971e807c8b11bf8224a50c9628b28f6/monet_bundle-1.0rc0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0a16af0d7f90d5c934de9b8eac84821bd81b008cbd4778e89555b9044dc10369",
                "md5": "42489bcb1ee54ab4e8d46d4536ab79ce",
                "sha256": "7cb5e231b95c759e9daa4fae37531af003e9e580900f2505947c071147cf9c24"
            },
            "downloads": -1,
            "filename": "monet_bundle-1.0rc0.tar.gz",
            "has_sig": false,
            "md5_digest": "42489bcb1ee54ab4e8d46d4536ab79ce",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 44692,
            "upload_time": "2025-07-12T14:43:50",
            "upload_time_iso_8601": "2025-07-12T14:43:50.580885Z",
            "url": "https://files.pythonhosted.org/packages/0a/16/af0d7f90d5c934de9b8eac84821bd81b008cbd4778e89555b9044dc10369/monet_bundle-1.0rc0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-12 14:43:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SimoneBendazzoli93",
    "github_project": "MONet-Bundle",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": null,
            "specs": []
        },
        {
            "name": null,
            "specs": []
        },
        {
            "name": null,
            "specs": []
        },
        {
            "name": "nvflare",
            "specs": []
        },
        {
            "name": "PyJWT",
            "specs": []
        },
        {
            "name": "python-on-whales",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "monet-bundle"
}
        
Elapsed time: 0.46350s