Name | nnInteractive JSON |
Version |
1.1.1
JSON |
| download |
home_page | None |
Summary | Inference code for nnInteractive |
upload_time | 2025-08-01 09:25:56 |
maintainer | None |
docs_url | None |
author | Helmholtz Imaging Applied Computer Vision Lab |
requires_python | >=3.10 |
license | Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [2019] [Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. |
keywords |
deep learning
image segmentation
semantic segmentation
medical image analysis
medical image segmentation
nnu-net
nnunet
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img src="imgs/nnInteractive_header_white.png">
# Python backend for `nnInteractive: Redefining 3D Promptable Segmentation`
This repository provides the official Python backend for `nnInteractive`, a state-of-the-art framework for 3D promptable segmentation. It is designed for seamless integration into Python-based workflows—ideal for researchers, developers, and power users working directly with code.
`nnInteractive` is also available through graphical viewers (GUI) for those who prefer a visual workflow. The napari and MITK integrations are developed and maintained by our team. Thanks to the community for contributing the 3D Slicer extension!
<div align="center">
| **<div align="center">[napari plugin](https://github.com/MIC-DKFZ/napari-nninteractive)</div>** | **<div align="center">[MITK integration](https://www.mitk.org/wiki/MITK-nnInteractive)</div>** | **<div align="center">[3D Slicer extension](https://github.com/coendevente/SlicerNNInteractive)</div>** | **<div align="center">[ITK-SNAP extension](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html)</div>** |
|-------------------|----------------------|-------------------------|-------------------------|
| [<img src="imgs/Logos/napari.jpg" height="200">](https://github.com/MIC-DKFZ/napari-nninteractive) | [<img src="imgs/Logos/mitk.jpg" height="200">](https://www.mitk.org/wiki/MITK-nnInteractive) | [<img src="imgs/Logos/3DSlicer.png" height="200">](https://github.com/coendevente/SlicerNNInteractive) | [<img src="imgs/Logos/snaplogo_sq.png" height="200">](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html) |
</div>
## 📰 News
- **07/2025**: 🧩 New ITK-SNAP extension released! Try nnInteractive directly in ITK-SNAP 👉 [Quick Start](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html)
- **06/2025**: 🏆 We’re thrilled to announce that `nnInteractive` **won the 1st place** in the [CVPR 2025 Challenge on Interactive 3D Segmentation](https://www.codabench.org/competitions/5263/). Huge shoutout to the organizers and all contributors!
- **05/2025**: `nnInteractive` presents an **official baseline** at **CVPR 2025** in the _Foundation Models for Interactive 3D Biomedical Image Segmentation Challenge_ ([Codabench link](https://www.codabench.org/competitions/5263/)) → see [`nnInteractive/inference/cvpr2025_challenge_baseline`](nnInteractive/inference/cvpr2025_challenge_baseline)
- **04/2025**: 🎉 The **community contributed a 3D Slicer integration** – thank you! 👉 [SlicerNNInteractive](https://github.com/coendevente/SlicerNNInteractive)
- **03/2025**: 🚀 `nnInteractive` **launched** with native support for **napari** and **MITK**
---
## What is nnInteractive?
> Isensee, F.\*, Rokuss, M.\*, Krämer, L.\*, Dinkelacker, S., Ravindran, A., Stritzke, F., Hamm, B., Wald, T., Langenberg, M., Ulrich, C., Deissler, J., Floca, R., & Maier-Hein, K. (2025). nnInteractive: Redefining 3D Promptable Segmentation. https://arxiv.org/abs/2503.08373 \
> *: equal contribution
Link: [](https://arxiv.org/abs/2503.08373)
##### Abstract:
Accurate and efficient 3D segmentation is essential for both clinical and research applications. While foundation
models like SAM have revolutionized interactive segmentation, their 2D design and domain shift limitations make them
ill-suited for 3D medical images. Current adaptations address some of these challenges but remain limited, either
lacking volumetric awareness, offering restricted interactivity, or supporting only a small set of structures and
modalities. Usability also remains a challenge, as current tools are rarely integrated into established imaging
platforms and often rely on cumbersome web-based interfaces with restricted functionality. We introduce nnInteractive,
the first comprehensive 3D interactive open-set segmentation method. It supports diverse prompts—including points,
scribbles, boxes, and a novel lasso prompt—while leveraging intuitive 2D interactions to generate full 3D
segmentations. Trained on 120+ diverse volumetric 3D datasets (CT, MRI, PET, 3D Microscopy, etc.), nnInteractive
sets a new state-of-the-art in accuracy, adaptability, and usability. Crucially, it is the first method integrated
into widely used image viewers (e.g., Napari, MITK), ensuring broad accessibility for real-world clinical and research
applications. Extensive benchmarking demonstrates that nnInteractive far surpasses existing methods, setting a new
standard for AI-driven interactive 3D segmentation.
<img src="imgs/figure1_method.png" width="1200">
## Installation
### Prerequisites
You need a Linux or Windows computer with a Nvidia GPU. 10GB of VRAM is recommended. Small objects should work with \<6GB.
##### 1. Create a virtual environment:
nnInteractive supports Python 3.10+ and works with Conda, pip, or any other virtual environment. Here’s an example using Conda:
```
conda create -n nnInteractive python=3.12
conda activate nnInteractive
```
##### 2. Install the correct PyTorch for your system
Go to the [PyTorch homepage](https://pytorch.org/get-started/locally/) and pick the right configuration.
Note that since recently PyTorch needs to be installed via pip. This is fine to do within your conda environment.
For Ubuntu with a Nvidia GPU, pick 'stable', 'Linux', 'Pip', 'Python', 'CUDA12.6' (if all drivers are up to date, otherwise use and older version):
```
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126
```
##### 3. Install this repository
Either install via pip:
`pip install nninteractive`
Or clone and install this repository:
```bash
git clone https://github.com/MIC-DKFZ/nnInteractive
cd nnInteractive
pip install -e .
```
## Getting Started
Here is a minimalistic script that covers the core functionality of nnInteractive:
```python
import os
import torch
import SimpleITK as sitk
from huggingface_hub import snapshot_download # Install huggingface_hub if not already installed
# --- Download Trained Model Weights (~400MB) ---
REPO_ID = "nnInteractive/nnInteractive"
MODEL_NAME = "nnInteractive_v1.0" # Updated models may be available in the future
DOWNLOAD_DIR = "/home/isensee/temp" # Specify the download directory
download_path = snapshot_download(
repo_id=REPO_ID,
allow_patterns=[f"{MODEL_NAME}/*"],
local_dir=DOWNLOAD_DIR
)
# The model is now stored in DOWNLOAD_DIR/MODEL_NAME.
# --- Initialize Inference Session ---
from nnInteractive.inference.inference_session import nnInteractiveInferenceSession
session = nnInteractiveInferenceSession(
device=torch.device("cuda:0"), # Set inference device
use_torch_compile=False, # Experimental: Not tested yet
verbose=False,
torch_n_threads=os.cpu_count(), # Use available CPU cores
do_autozoom=True, # Enables AutoZoom for better patching
use_pinned_memory=True, # Optimizes GPU memory transfers
)
# Load the trained model
model_path = os.path.join(DOWNLOAD_DIR, MODEL_NAME)
session.initialize_from_trained_model_folder(model_path)
# --- Load Input Image (Example with SimpleITK) ---
input_image = sitk.ReadImage("FILENAME")
img = sitk.GetArrayFromImage(input_image)[None] # Ensure shape (1, x, y, z)
# Validate input dimensions
if img.ndim != 4:
raise ValueError("Input image must be 4D with shape (1, x, y, z)")
session.set_image(img)
# --- Define Output Buffer ---
target_tensor = torch.zeros(img.shape[1:], dtype=torch.uint8) # Must be 3D (x, y, z)
session.set_target_buffer(target_tensor)
# --- Interacting with the Model ---
# Interactions can be freely chained and mixed in any order. Each interaction refines the segmentation.
# The model updates the segmentation mask in the target buffer after every interaction.
# Example: Add a **positive** point interaction
# POINT_COORDINATES should be a tuple (x, y, z) specifying the point location.
session.add_point_interaction(POINT_COORDINATES, include_interaction=True)
# Example: Add a **negative** point interaction
# To make any interaction negative set include_interaction=False
session.add_point_interaction(POINT_COORDINATES, include_interaction=False)
# Example: Add a bounding box interaction
# BBOX_COORDINATES must be specified as [[x1, x2], [y1, y2], [z1, z2]] (half-open intervals).
# Note: nnInteractive pre-trained models currently only support **2D bounding boxes**.
# This means that **one dimension must be [d, d+1]** to indicate a single slice.
# Example of a 2D bounding box in the axial plane (XY slice at depth Z)
# BBOX_COORDINATES = [[30, 80], [40, 100], [10, 11]] # X: 30-80, Y: 40-100, Z: slice 10
session.add_bbox_interaction(BBOX_COORDINATES, include_interaction=True)
# Example: Add a scribble interaction
# - A 3D image of the same shape as img where one slice (any axis-aligned orientation) contains a hand-drawn scribble.
# - Background must be 0, and scribble must be 1.
# - Use session.preferred_scribble_thickness for optimal results.
session.add_scribble_interaction(SCRIBBLE_IMAGE, include_interaction=True)
# Example: Add a lasso interaction
# - Similarly to scribble a 3D image with a single slice containing a **closed contour** representing the selection.
session.add_lasso_interaction(LASSO_IMAGE, include_interaction=True)
# You can combine any number of interactions as needed.
# The model refines the segmentation result incrementally with each new interaction.
# --- Retrieve Results ---
# The target buffer holds the segmentation result.
results = session.target_buffer.clone()
# OR (equivalent)
results = target_tensor.clone()
# Cloning is required because the buffer will be **reused** for the next object.
# Alternatively, set a new target buffer for each object:
session.set_target_buffer(torch.zeros(img.shape[1:], dtype=torch.uint8))
# --- Start a New Object Segmentation ---
session.reset_interactions() # Clears the target buffer and resets interactions
# Now you can start segmenting the next object in the image.
# --- Set a New Image ---
# Setting a new image also requires setting a new matching target buffer
session.set_image(NEW_IMAGE)
session.set_target_buffer(torch.zeros(NEW_IMAGE.shape[1:], dtype=torch.uint8))
# Enjoy!
```
## nnInteractive SuperVoxels
As part of the `nnInteractive` framework, we provide a dedicated module for **supervoxel generation** based on [SAM](https://github.com/facebookresearch/segment-anything) and [SAM2](https://github.com/facebookresearch/sam2). This replaces traditional superpixel methods (e.g., SLIC) with **foundation model–powered 3D pseudo-labels**.
🔗 **Module:** [`nnInteractive/supervoxel/`](nnInteractive/supervoxel)
The SuperVoxel module allows you to:
- Automatically generate high-quality 3D supervoxels via axial sampling + SAM segmentation and SAM2 mask propagation.
- Use the generated supervoxels as **pseudo-ground-truth labels** to train promptable 3D segmentation models like `nnInteractive`.
- Export `nnUNet`-compatible `.pkl` foreground prompts for downstream use.
For detailed installation, configuration, and usage instructions, check the [SuperVoxel README](nnInteractive/supervoxel/README.md).
## Citation
When using nnInteractive, please cite the following paper:
> Isensee, F.\*, Rokuss, M.\*, Krämer, L.\*, Dinkelacker, S., Ravindran, A., Stritzke, F., Hamm, B., Wald, T., Langenberg, M., Ulrich, C., Deissler, J., Floca, R., & Maier-Hein, K. (2025). nnInteractive: Redefining 3D Promptable Segmentation. https://arxiv.org/abs/2503.08373 \
> *: equal contribution
Link: [](https://arxiv.org/abs/2503.08373)
# License
Note that while this repository is available under Apache-2.0 license (see [LICENSE](./LICENSE)), the [model checkpoint](https://huggingface.co/nnInteractive/nnInteractive) is `Creative Commons Attribution Non Commercial Share Alike 4.0`!
# Changelog
### 1.1.1 - 2025-08-01
- We now detect whether linux kernel 6.11 is used and disable pin_memory in that case. See also [here](https://github.com/MIC-DKFZ/nnInteractive/issues/18)
- ✅ API compatible with 1.0.1 and 1.1.0
### 1.1.0 - 2025-08-01
- Reworked inference code. It's now well-structured and easier to follow.
- Fixed bugs that
- sometimes caused blocky predictions
- may cause failure to update segmentation map if changes were minor and AutoZoom was triggered
- ✅ API compatible with 1.0.1
## Acknowledgments
<p align="left">
<img src="imgs/Logos/HI_Logo.png" width="150">
<img src="imgs/Logos/DKFZ_Logo.png" width="500">
</p>
This repository is developed and maintained by the Applied Computer Vision Lab (ACVL)
of [Helmholtz Imaging](https://www.helmholtz-imaging.de/) and the
[Division of Medical Image Computing](https://www.dkfz.de/en/medical-image-computing) at DKFZ.
Raw data
{
"_id": null,
"home_page": null,
"name": "nnInteractive",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "deep learning, image segmentation, semantic segmentation, medical image analysis, medical image segmentation, nnU-Net, nnunet",
"author": "Helmholtz Imaging Applied Computer Vision Lab",
"author_email": "Fabian Isensee <f.isensee@dkfz-heidelberg.de>",
"download_url": "https://files.pythonhosted.org/packages/03/66/d3be0fd16909a2ea8c73b02a2beb872e03a9f69fcfbe5dc9c48de5c62bc1/nninteractive-1.1.1.tar.gz",
"platform": null,
"description": "<img src=\"imgs/nnInteractive_header_white.png\">\n\n# Python backend for `nnInteractive: Redefining 3D Promptable Segmentation`\n\nThis repository provides the official Python backend for `nnInteractive`, a state-of-the-art framework for 3D promptable segmentation. It is designed for seamless integration into Python-based workflows\u2014ideal for researchers, developers, and power users working directly with code.\n\n`nnInteractive` is also available through graphical viewers (GUI) for those who prefer a visual workflow. The napari and MITK integrations are developed and maintained by our team. Thanks to the community for contributing the 3D Slicer extension!\n\n\n<div align=\"center\">\n\n| **<div align=\"center\">[napari plugin](https://github.com/MIC-DKFZ/napari-nninteractive)</div>** | **<div align=\"center\">[MITK integration](https://www.mitk.org/wiki/MITK-nnInteractive)</div>** | **<div align=\"center\">[3D Slicer extension](https://github.com/coendevente/SlicerNNInteractive)</div>** | **<div align=\"center\">[ITK-SNAP extension](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html)</div>** |\n|-------------------|----------------------|-------------------------|-------------------------|\n| [<img src=\"imgs/Logos/napari.jpg\" height=\"200\">](https://github.com/MIC-DKFZ/napari-nninteractive) | [<img src=\"imgs/Logos/mitk.jpg\" height=\"200\">](https://www.mitk.org/wiki/MITK-nnInteractive) | [<img src=\"imgs/Logos/3DSlicer.png\" height=\"200\">](https://github.com/coendevente/SlicerNNInteractive) | [<img src=\"imgs/Logos/snaplogo_sq.png\" height=\"200\">](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html) |\n\n</div>\n\n\n## \ud83d\udcf0 News\n\n- **07/2025**: \ud83e\udde9 New ITK-SNAP extension released! Try nnInteractive directly in ITK-SNAP \ud83d\udc49 [Quick Start](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html)\n- **06/2025**: \ud83c\udfc6 We\u2019re thrilled to announce that `nnInteractive` **won the 1st place** in the [CVPR 2025 Challenge on Interactive 3D Segmentation](https://www.codabench.org/competitions/5263/). Huge shoutout to the organizers and all contributors!\n- **05/2025**: `nnInteractive` presents an **official baseline** at **CVPR 2025** in the _Foundation Models for Interactive 3D Biomedical Image Segmentation Challenge_ ([Codabench link](https://www.codabench.org/competitions/5263/)) \u2192 see [`nnInteractive/inference/cvpr2025_challenge_baseline`](nnInteractive/inference/cvpr2025_challenge_baseline)\n- **04/2025**: \ud83c\udf89 The **community contributed a 3D Slicer integration** \u2013 thank you! \ud83d\udc49 [SlicerNNInteractive](https://github.com/coendevente/SlicerNNInteractive)\n- **03/2025**: \ud83d\ude80 `nnInteractive` **launched** with native support for **napari** and **MITK**\n\n---\n\n\n## What is nnInteractive?\n\n> Isensee, F.\\*, Rokuss, M.\\*, Kr\u00e4mer, L.\\*, Dinkelacker, S., Ravindran, A., Stritzke, F., Hamm, B., Wald, T., Langenberg, M., Ulrich, C., Deissler, J., Floca, R., & Maier-Hein, K. (2025). nnInteractive: Redefining 3D Promptable Segmentation. https://arxiv.org/abs/2503.08373 \\\n> *: equal contribution\n\nLink: [](https://arxiv.org/abs/2503.08373)\n\n\n##### Abstract:\n\nAccurate and efficient 3D segmentation is essential for both clinical and research applications. While foundation \nmodels like SAM have revolutionized interactive segmentation, their 2D design and domain shift limitations make them \nill-suited for 3D medical images. Current adaptations address some of these challenges but remain limited, either \nlacking volumetric awareness, offering restricted interactivity, or supporting only a small set of structures and \nmodalities. Usability also remains a challenge, as current tools are rarely integrated into established imaging \nplatforms and often rely on cumbersome web-based interfaces with restricted functionality. We introduce nnInteractive, \nthe first comprehensive 3D interactive open-set segmentation method. It supports diverse prompts\u2014including points, \nscribbles, boxes, and a novel lasso prompt\u2014while leveraging intuitive 2D interactions to generate full 3D \nsegmentations. Trained on 120+ diverse volumetric 3D datasets (CT, MRI, PET, 3D Microscopy, etc.), nnInteractive \nsets a new state-of-the-art in accuracy, adaptability, and usability. Crucially, it is the first method integrated \ninto widely used image viewers (e.g., Napari, MITK), ensuring broad accessibility for real-world clinical and research \napplications. Extensive benchmarking demonstrates that nnInteractive far surpasses existing methods, setting a new \nstandard for AI-driven interactive 3D segmentation.\n\n<img src=\"imgs/figure1_method.png\" width=\"1200\">\n\n\n## Installation\n\n### Prerequisites\n\nYou need a Linux or Windows computer with a Nvidia GPU. 10GB of VRAM is recommended. Small objects should work with \\<6GB.\n\n##### 1. Create a virtual environment:\n\nnnInteractive supports Python 3.10+ and works with Conda, pip, or any other virtual environment. Here\u2019s an example using Conda:\n\n```\nconda create -n nnInteractive python=3.12\nconda activate nnInteractive\n```\n\n##### 2. Install the correct PyTorch for your system\n\nGo to the [PyTorch homepage](https://pytorch.org/get-started/locally/) and pick the right configuration.\nNote that since recently PyTorch needs to be installed via pip. This is fine to do within your conda environment.\n\nFor Ubuntu with a Nvidia GPU, pick 'stable', 'Linux', 'Pip', 'Python', 'CUDA12.6' (if all drivers are up to date, otherwise use and older version):\n\n```\npip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126\n```\n\n##### 3. Install this repository\nEither install via pip:\n`pip install nninteractive`\n\nOr clone and install this repository:\n```bash\ngit clone https://github.com/MIC-DKFZ/nnInteractive\ncd nnInteractive\npip install -e .\n```\n\n## Getting Started\nHere is a minimalistic script that covers the core functionality of nnInteractive:\n\n```python\nimport os\nimport torch\nimport SimpleITK as sitk\nfrom huggingface_hub import snapshot_download # Install huggingface_hub if not already installed\n\n# --- Download Trained Model Weights (~400MB) ---\nREPO_ID = \"nnInteractive/nnInteractive\"\nMODEL_NAME = \"nnInteractive_v1.0\" # Updated models may be available in the future\nDOWNLOAD_DIR = \"/home/isensee/temp\" # Specify the download directory\n\ndownload_path = snapshot_download(\n repo_id=REPO_ID,\n allow_patterns=[f\"{MODEL_NAME}/*\"],\n local_dir=DOWNLOAD_DIR\n)\n\n# The model is now stored in DOWNLOAD_DIR/MODEL_NAME.\n\n# --- Initialize Inference Session ---\nfrom nnInteractive.inference.inference_session import nnInteractiveInferenceSession\n\nsession = nnInteractiveInferenceSession(\n device=torch.device(\"cuda:0\"), # Set inference device\n use_torch_compile=False, # Experimental: Not tested yet\n verbose=False,\n torch_n_threads=os.cpu_count(), # Use available CPU cores\n do_autozoom=True, # Enables AutoZoom for better patching\n use_pinned_memory=True, # Optimizes GPU memory transfers\n)\n\n# Load the trained model\nmodel_path = os.path.join(DOWNLOAD_DIR, MODEL_NAME)\nsession.initialize_from_trained_model_folder(model_path)\n\n# --- Load Input Image (Example with SimpleITK) ---\ninput_image = sitk.ReadImage(\"FILENAME\")\nimg = sitk.GetArrayFromImage(input_image)[None] # Ensure shape (1, x, y, z)\n\n# Validate input dimensions\nif img.ndim != 4:\n raise ValueError(\"Input image must be 4D with shape (1, x, y, z)\")\n\nsession.set_image(img)\n\n# --- Define Output Buffer ---\ntarget_tensor = torch.zeros(img.shape[1:], dtype=torch.uint8) # Must be 3D (x, y, z)\nsession.set_target_buffer(target_tensor)\n\n# --- Interacting with the Model ---\n# Interactions can be freely chained and mixed in any order. Each interaction refines the segmentation.\n# The model updates the segmentation mask in the target buffer after every interaction.\n\n# Example: Add a **positive** point interaction\n# POINT_COORDINATES should be a tuple (x, y, z) specifying the point location.\nsession.add_point_interaction(POINT_COORDINATES, include_interaction=True)\n\n# Example: Add a **negative** point interaction\n# To make any interaction negative set include_interaction=False\nsession.add_point_interaction(POINT_COORDINATES, include_interaction=False)\n\n# Example: Add a bounding box interaction\n# BBOX_COORDINATES must be specified as [[x1, x2], [y1, y2], [z1, z2]] (half-open intervals).\n# Note: nnInteractive pre-trained models currently only support **2D bounding boxes**.\n# This means that **one dimension must be [d, d+1]** to indicate a single slice.\n\n# Example of a 2D bounding box in the axial plane (XY slice at depth Z)\n# BBOX_COORDINATES = [[30, 80], [40, 100], [10, 11]] # X: 30-80, Y: 40-100, Z: slice 10\n\nsession.add_bbox_interaction(BBOX_COORDINATES, include_interaction=True)\n\n# Example: Add a scribble interaction\n# - A 3D image of the same shape as img where one slice (any axis-aligned orientation) contains a hand-drawn scribble.\n# - Background must be 0, and scribble must be 1.\n# - Use session.preferred_scribble_thickness for optimal results.\nsession.add_scribble_interaction(SCRIBBLE_IMAGE, include_interaction=True)\n\n# Example: Add a lasso interaction\n# - Similarly to scribble a 3D image with a single slice containing a **closed contour** representing the selection.\nsession.add_lasso_interaction(LASSO_IMAGE, include_interaction=True)\n\n# You can combine any number of interactions as needed. \n# The model refines the segmentation result incrementally with each new interaction.\n\n# --- Retrieve Results ---\n# The target buffer holds the segmentation result.\nresults = session.target_buffer.clone()\n# OR (equivalent)\nresults = target_tensor.clone()\n\n# Cloning is required because the buffer will be **reused** for the next object.\n# Alternatively, set a new target buffer for each object:\nsession.set_target_buffer(torch.zeros(img.shape[1:], dtype=torch.uint8))\n\n# --- Start a New Object Segmentation ---\nsession.reset_interactions() # Clears the target buffer and resets interactions\n\n# Now you can start segmenting the next object in the image.\n\n# --- Set a New Image ---\n# Setting a new image also requires setting a new matching target buffer\nsession.set_image(NEW_IMAGE)\nsession.set_target_buffer(torch.zeros(NEW_IMAGE.shape[1:], dtype=torch.uint8))\n\n# Enjoy!\n```\n\n## nnInteractive SuperVoxels\n\nAs part of the `nnInteractive` framework, we provide a dedicated module for **supervoxel generation** based on [SAM](https://github.com/facebookresearch/segment-anything) and [SAM2](https://github.com/facebookresearch/sam2). This replaces traditional superpixel methods (e.g., SLIC) with **foundation model\u2013powered 3D pseudo-labels**.\n\n\ud83d\udd17 **Module:** [`nnInteractive/supervoxel/`](nnInteractive/supervoxel)\n\nThe SuperVoxel module allows you to:\n\n- Automatically generate high-quality 3D supervoxels via axial sampling + SAM segmentation and SAM2 mask propagation.\n- Use the generated supervoxels as **pseudo-ground-truth labels** to train promptable 3D segmentation models like `nnInteractive`.\n- Export `nnUNet`-compatible `.pkl` foreground prompts for downstream use.\n\nFor detailed installation, configuration, and usage instructions, check the [SuperVoxel README](nnInteractive/supervoxel/README.md).\n\n\n## Citation\nWhen using nnInteractive, please cite the following paper:\n\n> Isensee, F.\\*, Rokuss, M.\\*, Kr\u00e4mer, L.\\*, Dinkelacker, S., Ravindran, A., Stritzke, F., Hamm, B., Wald, T., Langenberg, M., Ulrich, C., Deissler, J., Floca, R., & Maier-Hein, K. (2025). nnInteractive: Redefining 3D Promptable Segmentation. https://arxiv.org/abs/2503.08373 \\\n> *: equal contribution\n\nLink: [](https://arxiv.org/abs/2503.08373)\n\n\n# License\nNote that while this repository is available under Apache-2.0 license (see [LICENSE](./LICENSE)), the [model checkpoint](https://huggingface.co/nnInteractive/nnInteractive) is `Creative Commons Attribution Non Commercial Share Alike 4.0`! \n\n# Changelog\n\n### 1.1.1 - 2025-08-01\n\n- We now detect whether linux kernel 6.11 is used and disable pin_memory in that case. See also [here](https://github.com/MIC-DKFZ/nnInteractive/issues/18)\n- \u2705 API compatible with 1.0.1 and 1.1.0\n\n### 1.1.0 - 2025-08-01\n\n- Reworked inference code. It's now well-structured and easier to follow.\n- Fixed bugs that \n - sometimes caused blocky predictions\n - may cause failure to update segmentation map if changes were minor and AutoZoom was triggered\n- \u2705 API compatible with 1.0.1\n\n## Acknowledgments\n\n<p align=\"left\">\n <img src=\"imgs/Logos/HI_Logo.png\" width=\"150\"> \n <img src=\"imgs/Logos/DKFZ_Logo.png\" width=\"500\">\n</p>\n\nThis repository is developed and maintained by the Applied Computer Vision Lab (ACVL)\nof [Helmholtz Imaging](https://www.helmholtz-imaging.de/) and the \n[Division of Medical Image Computing](https://www.dkfz.de/en/medical-image-computing) at DKFZ.\n",
"bugtrack_url": null,
"license": "Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n \n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n \n 1. Definitions.\n \n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n \n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n \n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n \n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n \n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n \n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n \n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n \n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n \n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n \n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n \n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n \n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n \n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n \n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n \n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n \n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n \n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n \n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n \n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n \n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n \n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n \n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n \n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n \n END OF TERMS AND CONDITIONS\n \n APPENDIX: How to apply the Apache License to your work.\n \n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n \n Copyright [2019] [Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany]\n \n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.",
"summary": "Inference code for nnInteractive",
"version": "1.1.1",
"project_urls": {
"homepage": "https://github.com/MIC-DKFZ/nnInteractive"
},
"split_keywords": [
"deep learning",
" image segmentation",
" semantic segmentation",
" medical image analysis",
" medical image segmentation",
" nnu-net",
" nnunet"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0366d3be0fd16909a2ea8c73b02a2beb872e03a9f69fcfbe5dc9c48de5c62bc1",
"md5": "a54ecb26bcb01d05a9c4528192798d30",
"sha256": "ad4e38ed355f741048c9beceb9697dad94548274da27d478d430a59a345c3288"
},
"downloads": -1,
"filename": "nninteractive-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a54ecb26bcb01d05a9c4528192798d30",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 177259,
"upload_time": "2025-08-01T09:25:56",
"upload_time_iso_8601": "2025-08-01T09:25:56.380124Z",
"url": "https://files.pythonhosted.org/packages/03/66/d3be0fd16909a2ea8c73b02a2beb872e03a9f69fcfbe5dc9c48de5c62bc1/nninteractive-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-01 09:25:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MIC-DKFZ",
"github_project": "nnInteractive",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nninteractive"
}