lefusion-slicer

3DSlicer plugin for inpainting lung nodules in 3D chest CT data.

https://github.com/pedr0sorio/lefusion-slicer

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.7%) to scientific vocabulary

Keywords

3dslicer inpainting lung-ct lung-nodule
Last synced: 6 months ago · JSON representation ·

Repository

3DSlicer plugin for inpainting lung nodules in 3D chest CT data.

Basic Info
  • Host: GitHub
  • Owner: pedr0sorio
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 19.2 MB
Statistics
  • Stars: 10
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
3dslicer inpainting lung-ct lung-nodule
Created over 1 year ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

LeFusion 3D Slicer Plugin

Overview

This repository contains a plugin for 3D slicer that integrates the LeFusion model for 3D lung nodule inpainting in chest CT.

It is composed of the code related to the slicer extension + the code related to the backend server where the inpainiting computations are done.

[!NOTE]
You can have both the server and slicer running on the same local machine if you have a GPU connected to it. Otherwise, you can have the server running on a remote machine attached to a GPU and access it via port forwarding.

Installation

Inpainting (LeFusion) Backend Setup

  • Download the code: git clone https://github.com/pedr0sorio/lefusion-slicer.git
  • Enter the LeFusion folder cd lefusion-slicer/server
  • Create a virtual environment and activate it and install repo with poetry like so:

```bash

assuming lefusion-slicer/server

conda env create -f environment.yml conda activate lefusion poetry config virtualenvs.create false poetry install ```

Download the pre-trained LeFusion Model (HuggingFace🤗)

The LeFusion authors pre-trained LeFusion Model, which has been trained for 50,001 steps on the LIDC-IDRI dataset. This pre-trained model can be directly used for Inference. Simply download it to server/lefusion/LeFusion_model.

bash # Assuming cd is lefusion-slicer/server cd lefusion mkdir LeFusion_model cd LeFusion_model wget https://huggingface.co/YuheLiuu/LeFusion/resolve/main/LIDC_LeFusion_Model/model-50.pt -O model-50.pt

Plugin Setup

  • Install 3D Slicer from its official website. The compatibility of our plugin has been tested with 3D Slicer >= 5.6.2
  • Select the Welcome to Slicer drop-down menu in the toolbar at the top and navigate to Developer Tools > Extension Wizard.
  • Click on select Extension and locate the MedSAM2 folder under MedSAM2/slicer. Confirm if asked to import new module.
  • Now, from the Welcome to Slicer drop-down menu, under the Segmentation sub-menu, MedSAM2 option is added. By choosing it, you can start using the plugin.

Getting Started

1. Run the backend

You have to run the inpainting server to accept the incoming inpainting requests from slicer. You can do it both locally or on a remote computer:

```bash

 from lefusion-slicer/server

python server.py ```

This runs the server on the public interface of your device on port 8888.

2. Basic plugin usage

The notes present in the UI should explain how to use the inpainting tool. For visual support refer to the .gif above.

The Jump Length and Jump Number parameters control how many RePaint inference steps will be used to generate the lesions in the batch. Following the author's notes and also according to my experience using a value of 2 for both parameters offers the best compromise between lesion quality and compute time.

On a A100 for default inference parameters the total processing time is approximately:

| Lesions in Batch | (1,1) | (2,2) | |------------------|-------|----------| | 1 | 30s | 1min | | 2 | 50s | 1min 30s | | 3 | - | 2min 16s | | 4 | - | 2min 52s |

[!NOTE]
I have been using a 40GB A100, which allows be to generate multiple lesions at once. Please adjust the batch size accoridng to you GPU. It is possible to run the server on a T4 GPU but batches would have to be reduced to a single lesion and teh total processing time soars up to 3min 30s / lesion.

[!NOTE]
As of now due to the lack of the DiffMask (see LeFusion paper) weights and code, the lesion mask for the selected crop will not be inferred but chosen randomly from a set of LIDC-IDRI masks already extracted by the original authors. They are saved under server/in/mask-asset.

Contact

For any questions or issues, please open an issue on this repository or contact me at [pedro.c.osorio@gmail.com].

Citation

If you are using this in your work, please cite both THIS REPO as defined in citation.cff and the original LeFusion paper.

Acknowledgement

This repo is based on some code from MedSAMSlicer and the inference code from LeFusion original authors LeFusion.

ToDo List ✅

ROI selection and volume editing in 3D slicer

Sending and retrieving the volumes from the server

Server side, processing, inference and return to client

🔲 Add DiffMask to infer mask from crop

🔲 Setting server running on Vertex AI inference endpoint

🔲 Further document codebase

🔲 Update ReadMe

🔲 Publish extension

Owner

  • Name: Pedro Osório
  • Login: pedr0sorio
  • Kind: user
  • Location: Berlin, Germany

I am MSc Finalist in Biomedical Engineering, interested in AI and its applications in health care. Currently working as an intern at Bayer AG.

Citation (citation.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: 'CT Lung Nodule Inpainting: A LeFusion 3DSlicer Extension'
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Pedro
    family-names: Osorio
    email: pedro.c.osorio@gmail.com
    orcid: 'https://orcid.org/0009-0006-8848-0214'
repository-code: 'https://github.com/pedr0sorio/lefusion-slicer'
abstract: >-
  This repository contains a plugin for 3D slicer that
  integrates the LeFusion model for 3D lung nodule
  inpainting in chest CT.
keywords:
  - lung nodules
  - ct
  - Inpainiting
  - 3D
license: MIT

GitHub Events

Total
  • Issues event: 2
  • Watch event: 11
  • Issue comment event: 1
  • Push event: 10
  • Pull request event: 2
  • Create event: 1
Last Year
  • Issues event: 2
  • Watch event: 11
  • Issue comment event: 1
  • Push event: 10
  • Pull request event: 2
  • Create event: 1

Dependencies

server/requirements-jupyter.txt pypi
  • ipykernel >=6.27.0
  • jupyter >=1.0.0
  • jupyter_resource_usage >=1.0.1
  • jupyter_server_fileid >=0.9.0
  • jupyter_server_mathjax >=0.2.6
  • jupyter_server_ydoc >=0.8.0
  • jupyterlab_code_formatter >=2.2.1
  • jupyterlab_git >=0.50.0
  • jupyterlab_iframe >=0.5.0
  • jupyterlab_spellchecker >=0.8.4
  • nbclassic >=1.0.0
  • nbdime >=4.0.1
server/requirements.txt pypi
  • Deprecated ==1.2.13
  • Flask ==3.0.3
  • GitPython ==3.1.27
  • Jinja2 ==3.1.4
  • Markdown ==3.3.7
  • MarkupSafe ==2.1.5
  • Pillow ==9.1.1
  • PyWavelets ==1.3.0
  • PyYAML ==6.0
  • SimpleITK ==2.1.1.2
  • Werkzeug *
  • absl-py ==1.1.0
  • accelerate ==0.11.0
  • aiohttp ==3.8.1
  • aiosignal ==1.2.0
  • antlr4-python3-runtime ==4.9.3
  • async-timeout ==4.0.2
  • attrs ==21.4.0
  • autopep8 ==1.6.0
  • blessed ==1.20.0
  • blobfile ==2.1.1
  • cachetools ==5.2.0
  • certifi ==2022.6.15
  • charset-normalizer ==2.0.12
  • click ==8.1.3
  • contextlib2 ==21.6.0
  • cycler ==0.11.0
  • docker-pycreds ==0.4.0
  • einops ==0.4.1
  • einops-exts ==0.0.3
  • elasticdeform ==0.5.1
  • ema-pytorch ==0.0.8
  • filelock ==3.15.4
  • fonttools ==4.34.4
  • frozenlist ==1.3.0
  • fsspec ==2022.5.0
  • ftfy ==6.1.1
  • future ==0.18.2
  • gitdb ==4.0.9
  • glob2 ==0.7
  • google-auth ==2.9.0
  • google-auth-oauthlib ==0.4.6
  • gpustat ==1.1.1
  • grpcio ==1.47.0
  • h5py ==3.7.0
  • huggingface-hub ==0.17.3
  • humanize ==4.2.2
  • hydra-core ==1.2.0
  • idna ==3.3
  • imageio ==2.19.3
  • imageio-ffmpeg ==0.4.7
  • importlib-metadata ==4.12.0
  • importlib-resources ==5.9.0
  • joblib ==1.1.0
  • kiwisolver ==1.4.3
  • lxml ==4.9.1
  • matplotlib ==3.5.2
  • ml_collections ==0.1.1
  • monai ==0.9.0
  • mpmath ==1.3.0
  • multidict ==6.0.2
  • networkx ==2.8.5
  • nibabel ==4.0.1
  • nilearn ==0.9.1
  • numpy ==1.23.0
  • nvidia-cublas-cu12 ==12.1.3.1
  • nvidia-cuda-cupti-cu12 ==12.1.105
  • nvidia-cuda-nvrtc-cu12 ==12.1.105
  • nvidia-cuda-runtime-cu12 ==12.1.105
  • nvidia-cudnn-cu12 ==8.9.2.26
  • nvidia-cufft-cu12 ==11.0.2.54
  • nvidia-curand-cu12 ==10.3.2.106
  • nvidia-cusolver-cu12 ==11.4.5.107
  • nvidia-cusparse-cu12 ==12.1.0.106
  • nvidia-ml-py ==12.560.30
  • nvidia-nccl-cu12 ==2.18.1
  • nvidia-nvjitlink-cu12 ==12.6.20
  • nvidia-nvtx-cu12 ==12.1.105
  • oauthlib ==3.2.0
  • omegaconf ==2.2.3
  • opencv-python ==4.10.0.84
  • packaging ==24.1
  • pandas ==1.4.3
  • pathtools ==0.1.2
  • promise ==2.3
  • protobuf ==3.20.1
  • psutil ==6.0.0
  • pyDeprecate ==0.3.1
  • pyasn1 ==0.4.8
  • pyasn1-modules ==0.2.8
  • pycodestyle ==2.8.0
  • pycryptodomex ==3.21.0
  • pydicom ==2.3.0
  • pyparsing ==3.1.2
  • python-dateutil ==2.9.0.post0
  • pytorch-lightning ==1.6.4
  • pytz ==2022.1
  • pyzmq ==19.0.2
  • regex ==2022.6.2
  • requests ==2.28.0
  • requests-oauthlib ==1.3.1
  • rotary-embedding-torch ==0.1.5
  • rsa ==4.8
  • safetensors ==0.4.4
  • scikit-image ==0.19.3
  • scikit-learn ==1.1.2
  • scikit-video ==1.1.11
  • scipy ==1.8.1
  • seaborn ==0.11.2
  • sentry-sdk ==1.7.2
  • setproctitle ==1.2.3
  • shortuuid ==1.0.9
  • six ==1.16.0
  • sk-video ==1.1.10
  • smmap ==5.0.0
  • sympy ==1.13.1
  • tensorboard *
  • threadpoolctl ==3.1.0
  • tifffile ==2022.8.3
  • timm ==1.0.8
  • toml ==0.10.2
  • torch ==2.1.2
  • torch-tb-profiler ==0.4.0
  • torchio ==0.18.80
  • torchmetrics ==0.9.1
  • torchstat ==0.0.7
  • torchvision ==0.16.2
  • tqdm ==4.64.0
  • triton ==2.1.0
  • typing_extensions ==4.2.0
  • urllib3 ==1.26.9
  • wandb ==0.12.21
  • wcwidth ==0.2.13
  • wrapt ==1.14.1
  • yarl ==1.7.2
  • zipp ==3.8.0
server/environment.yml pypi
  • Deprecated ==1.2.13
  • Flask ==3.0.3
  • GitPython ==3.1.27
  • Jinja2 ==3.1.4
  • Markdown ==3.3.7
  • MarkupSafe ==2.1.5
  • MedPy ==0.5.0
  • Pillow ==9.1.1
  • PyWavelets ==1.3.0
  • PyYAML ==6.0
  • SimpleITK ==2.1.1.2
  • Werkzeug >=3.0.0
  • absl-py ==1.1.0
  • accelerate ==0.11.0
  • aiohttp ==3.8.1
  • aiosignal ==1.2.0
  • antlr4-python3-runtime ==4.9.3
  • async-timeout ==4.0.2
  • attrs ==21.4.0
  • autopep8 ==1.6.0
  • blessed ==1.20.0
  • blobfile ==2.1.1
  • cachetools ==5.2.0
  • certifi ==2022.6.15
  • charset-normalizer ==2.0.12
  • click ==8.1.3
  • contextlib2 ==21.6.0
  • cycler ==0.11.0
  • docker-pycreds ==0.4.0
  • einops ==0.4.1
  • einops-exts ==0.0.3
  • elasticdeform ==0.5.1
  • ema-pytorch ==0.0.8
  • filelock ==3.15.4
  • fonttools ==4.34.4
  • frozenlist ==1.3.0
  • fsspec ==2022.5.0
  • ftfy ==6.1.1
  • future ==0.18.2
  • gitdb ==4.0.9
  • glob2 ==0.7
  • google-auth ==2.9.0
  • google-auth-oauthlib ==0.4.6
  • gpustat ==1.1.1
  • grpcio ==1.47.0
  • h5py ==3.7.0
  • huggingface-hub ==0.17.3
  • humanize ==4.2.2
  • hydra-core ==1.2.0
  • idna ==3.3
  • imageio ==2.19.3
  • imageio-ffmpeg ==0.4.7
  • importlib-metadata ==4.12.0
  • importlib-resources ==5.9.0
  • joblib ==1.1.0
  • kiwisolver ==1.4.3
  • lxml ==4.9.1
  • matplotlib ==3.5.2
  • ml_collections ==0.1.1
  • monai ==0.9.0
  • mpmath ==1.3.0
  • multidict ==6.0.2
  • networkx ==2.8.5
  • nibabel ==4.0.1
  • nilearn ==0.9.1
  • numpy ==1.24.0
  • nvidia-cublas-cu12 ==12.1.3.1
  • nvidia-cuda-cupti-cu12 ==12.1.105
  • nvidia-cuda-nvrtc-cu12 ==12.1.105
  • nvidia-cuda-runtime-cu12 ==12.1.105
  • nvidia-cudnn-cu12 ==8.9.2.26
  • nvidia-cufft-cu12 ==11.0.2.54
  • nvidia-curand-cu12 ==10.3.2.106
  • nvidia-cusolver-cu12 ==11.4.5.107
  • nvidia-cusparse-cu12 ==12.1.0.106
  • nvidia-ml-py ==12.560.30
  • nvidia-nccl-cu12 ==2.18.1
  • nvidia-nvjitlink-cu12 ==12.6.20
  • nvidia-nvtx-cu12 ==12.1.105
  • oauthlib ==3.2.0
  • omegaconf ==2.2.3
  • opencv-python ==4.10.0.84
  • packaging ==24.1
  • pandas ==1.4.3
  • pathtools ==0.1.2
  • poetry *
  • promise ==2.3
  • protobuf ==3.20.1
  • psutil ==6.0.0
  • pyDeprecate ==0.3.1
  • pyasn1 ==0.4.8
  • pyasn1-modules ==0.2.8
  • pycodestyle ==2.8.0
  • pycryptodomex ==3.21.0
  • pydicom ==2.3.0
  • pylidc ==0.2.3
  • pyparsing ==3.1.2
  • python-dateutil ==2.9.0.post0
  • pytorch-lightning ==1.6.4
  • pytz ==2022.1
  • pyzmq ==19.0.2
  • regex ==2022.6.2
  • requests ==2.28.0
  • requests-oauthlib ==1.3.1
  • rotary-embedding-torch ==0.1.5
  • rsa ==4.8
  • safetensors ==0.4.4
  • scikit-image ==0.19.3
  • scikit-learn ==1.1.2
  • scikit-video ==1.1.11
  • scipy ==1.14.1
  • seaborn ==0.11.2
  • sentry-sdk ==1.7.2
  • setproctitle ==1.2.3
  • shortuuid ==1.0.9
  • six ==1.16.0
  • sk-video ==1.1.10
  • smmap ==5.0.0
  • sympy ==1.13.1
  • tensorboard ==2.11.2
  • tensorboard-data-server ==0.6.1
  • tensorboard-plugin-wit ==1.8.1
  • tensorboardX ==2.4.1
  • threadpoolctl ==3.1.0
  • tifffile ==2022.8.3
  • timm ==1.0.8
  • toml ==0.10.2
  • torch ==2.1.2
  • torch-tb-profiler ==0.4.0
  • torchio ==0.18.80
  • torchmetrics ==0.9.1
  • torchstat ==0.0.7
  • torchvision ==0.16.2
  • tqdm ==4.64.0
  • triton ==2.1.0
  • typing_extensions ==4.2.0
  • urllib3 ==1.26.9
  • wandb ==0.12.21
  • wcwidth ==0.2.13
  • wrapt ==1.14.1
  • yarl ==1.7.2
  • zipp ==3.8.0
server/poetry.lock pypi
server/pyproject.toml pypi
  • python >=3.10