Image Segmentation
Fabian Isensee commited on
Commit
3f308d7
·
1 Parent(s): 6d5c0f2
Files changed (2) hide show
  1. README.md +16 -194
  2. imgs/Logos/ohif.png +0 -0
README.md CHANGED
@@ -7,33 +7,25 @@ pipeline_tag: image-segmentation
7
 
8
  # nnInteractive: Redefining 3D Promptable Segmentation
9
 
10
- This repository provides the official checkpoints for `nnInteractive`, a state-of-the-art framework for 3D promptable segmentation.
11
- Check out the corresponding [python backend](https://github.com/MIC-DKFZ/nnInteractive).
12
- The backend is designed for seamless integration into Python-based workflows—ideal for researchers, developers, and power users working directly with code.
13
- `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!
14
 
 
 
 
 
15
 
 
16
 
17
  <div align="center">
18
 
19
- | **<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>** |
20
- |-------------------|----------------------|-------------------------|-------------------------|
21
- | [<img src="imgs/Logos/napari.jpg" width="200">](https://github.com/MIC-DKFZ/napari-nninteractive) | [<img src="imgs/Logos/mitk.jpg" width="200">](https://www.mitk.org/wiki/MITK-nnInteractive) | [<img src="imgs/Logos/3DSlicer.png" width="200">](https://github.com/coendevente/SlicerNNInteractive) | [<img src="imgs/Logos/snaplogo_sq.png" width="200">](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html) |
22
 
23
  </div>
24
 
25
-
26
- ## 📰 News
27
-
28
- - **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)
29
- - **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!
30
- - **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)
31
- - **04/2025**: 🎉 The **community contributed a 3D Slicer integration** – thank you! 👉 [SlicerNNInteractive](https://github.com/coendevente/SlicerNNInteractive)
32
- - **03/2025**: 🚀 `nnInteractive` **launched** with native support for **napari** and **MITK**
33
-
34
  ---
35
 
36
-
37
  ## What is nnInteractive?
38
 
39
  > 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 \
@@ -41,7 +33,6 @@ The backend is designed for seamless integration into Python-based workflows—i
41
 
42
  Link: [![arXiv](https://img.shields.io/badge/arXiv-2503.08373-b31b1b.svg)](https://arxiv.org/abs/2503.08373)
43
 
44
-
45
  ##### Abstract:
46
 
47
  Accurate and efficient 3D segmentation is essential for both clinical and research applications. While foundation
@@ -60,172 +51,24 @@ standard for AI-driven interactive 3D segmentation.
60
 
61
  <img src="imgs/figure1_method.png" width="1200">
62
 
 
63
 
64
- ## Installation
65
-
66
- ### Prerequisites
67
-
68
- You need a Linux or Windows computer with a Nvidia GPU. 10GB of VRAM is recommended. Small objects should work with \<6GB.
69
-
70
- ##### 1. Create a virtual environment:
71
-
72
- nnInteractive supports Python 3.10+ and works with Conda, pip, or any other virtual environment. Here’s an example using Conda:
73
-
74
- ```
75
- conda create -n nnInteractive python=3.12
76
- conda activate nnInteractive
77
- ```
78
-
79
- ##### 2. Install the correct PyTorch for your system
80
-
81
- Go to the [PyTorch homepage](https://pytorch.org/get-started/locally/) and pick the right configuration.
82
- Note that since recently PyTorch needs to be installed via pip. This is fine to do within your conda environment.
83
-
84
- 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):
85
-
86
- ```
87
- pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126
88
- ```
89
-
90
- ##### 3. Install this repository
91
- Either install via pip:
92
- `pip install nninteractive`
93
-
94
- Or clone and install this repository:
95
- ```bash
96
- git clone https://github.com/MIC-DKFZ/nnInteractive
97
- cd nnInteractive
98
- pip install -e .
99
- ```
100
-
101
- ## Getting Started
102
- Here is a minimalistic script that covers the core functionality of nnInteractive:
103
 
104
  ```python
105
- import os
106
- import torch
107
- import SimpleITK as sitk
108
- from huggingface_hub import snapshot_download # Install huggingface_hub if not already installed
109
 
110
- # --- Download Trained Model Weights (~400MB) ---
111
  REPO_ID = "nnInteractive/nnInteractive"
112
  MODEL_NAME = "nnInteractive_v1.0" # Updated models may be available in the future
113
- DOWNLOAD_DIR = "/home/isensee/temp" # Specify the download directory
114
 
115
  download_path = snapshot_download(
116
  repo_id=REPO_ID,
117
  allow_patterns=[f"{MODEL_NAME}/*"],
118
- local_dir=DOWNLOAD_DIR
119
  )
120
-
121
- # The model is now stored in DOWNLOAD_DIR/MODEL_NAME.
122
-
123
- # --- Initialize Inference Session ---
124
- from nnInteractive.inference.inference_session import nnInteractiveInferenceSession
125
-
126
- session = nnInteractiveInferenceSession(
127
- device=torch.device("cuda:0"), # Set inference device
128
- use_torch_compile=False, # Experimental: Not tested yet
129
- verbose=False,
130
- torch_n_threads=os.cpu_count(), # Use available CPU cores
131
- do_autozoom=True, # Enables AutoZoom for better patching
132
- use_pinned_memory=True, # Optimizes GPU memory transfers
133
- )
134
-
135
- # Load the trained model
136
- model_path = os.path.join(DOWNLOAD_DIR, MODEL_NAME)
137
- session.initialize_from_trained_model_folder(model_path)
138
-
139
- # --- Load Input Image (Example with SimpleITK) ---
140
- # DO NOT preprocess the image in any way. Give it to nnInteractive as it is! DO NOT apply level window, DO NOT normalize
141
- # intensities and never ever convert an image with higher precision (float32, uint16, etc) to uint8!
142
- # The ONLY instance where some preprocesing makes sense is if your original image is too large to be reasonably used.
143
- # This may be the case, for example, for some microCT images. In this case you can consider downsampling.
144
- input_image = sitk.ReadImage("FILENAME")
145
- img = sitk.GetArrayFromImage(input_image)[None] # Ensure shape (1, x, y, z)
146
-
147
- # Validate input dimensions
148
- if img.ndim != 4:
149
- raise ValueError("Input image must be 4D with shape (1, x, y, z)")
150
-
151
- session.set_image(img)
152
-
153
- # --- Define Output Buffer ---
154
- target_tensor = torch.zeros(img.shape[1:], dtype=torch.uint8) # Must be 3D (x, y, z)
155
- session.set_target_buffer(target_tensor)
156
-
157
- # --- Interacting with the Model ---
158
- # Interactions can be freely chained and mixed in any order. Each interaction refines the segmentation.
159
- # The model updates the segmentation mask in the target buffer after every interaction.
160
-
161
- # Example: Add a **positive** point interaction
162
- # POINT_COORDINATES should be a tuple (x, y, z) specifying the point location.
163
- session.add_point_interaction(POINT_COORDINATES, include_interaction=True)
164
-
165
- # Example: Add a **negative** point interaction
166
- # To make any interaction negative set include_interaction=False
167
- session.add_point_interaction(POINT_COORDINATES, include_interaction=False)
168
-
169
- # Example: Add a bounding box interaction
170
- # BBOX_COORDINATES must be specified as [[x1, x2], [y1, y2], [z1, z2]] (half-open intervals).
171
- # Note: nnInteractive pre-trained models currently only support **2D bounding boxes**.
172
- # This means that **one dimension must be [d, d+1]** to indicate a single slice.
173
-
174
- # Example of a 2D bounding box in the axial plane (XY slice at depth Z)
175
- # BBOX_COORDINATES = [[30, 80], [40, 100], [10, 11]] # X: 30-80, Y: 40-100, Z: slice 10
176
-
177
- session.add_bbox_interaction(BBOX_COORDINATES, include_interaction=True)
178
-
179
- # Example: Add a scribble interaction
180
- # - A 3D image of the same shape as img where one slice (any axis-aligned orientation) contains a hand-drawn scribble.
181
- # - Background must be 0, and scribble must be 1.
182
- # - Use session.preferred_scribble_thickness for optimal results.
183
- session.add_scribble_interaction(SCRIBBLE_IMAGE, include_interaction=True)
184
-
185
- # Example: Add a lasso interaction
186
- # - Similarly to scribble a 3D image with a single slice containing a **closed contour** representing the selection.
187
- session.add_lasso_interaction(LASSO_IMAGE, include_interaction=True)
188
-
189
- # You can combine any number of interactions as needed.
190
- # The model refines the segmentation result incrementally with each new interaction.
191
-
192
- # --- Retrieve Results ---
193
- # The target buffer holds the segmentation result.
194
- results = session.target_buffer.clone()
195
- # OR (equivalent)
196
- results = target_tensor.clone()
197
-
198
- # Cloning is required because the buffer will be **reused** for the next object.
199
- # Alternatively, set a new target buffer for each object:
200
- session.set_target_buffer(torch.zeros(img.shape[1:], dtype=torch.uint8))
201
-
202
- # --- Start a New Object Segmentation ---
203
- session.reset_interactions() # Clears the target buffer and resets interactions
204
-
205
- # Now you can start segmenting the next object in the image.
206
-
207
- # --- Set a New Image ---
208
- # Setting a new image also requires setting a new matching target buffer
209
- session.set_image(NEW_IMAGE)
210
- session.set_target_buffer(torch.zeros(NEW_IMAGE.shape[1:], dtype=torch.uint8))
211
-
212
- # Enjoy!
213
  ```
214
 
215
- ## nnInteractive SuperVoxels
216
-
217
- 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**.
218
-
219
- 🔗 **Module:** [`nnInteractive/supervoxel/`](nnInteractive/supervoxel)
220
-
221
- The SuperVoxel module allows you to:
222
-
223
- - Automatically generate high-quality 3D supervoxels via axial sampling + SAM segmentation and SAM2 mask propagation.
224
- - Use the generated supervoxels as **pseudo-ground-truth labels** to train promptable 3D segmentation models like `nnInteractive`.
225
- - Export `nnUNet`-compatible `.pkl` foreground prompts for downstream use.
226
-
227
- For detailed installation, configuration, and usage instructions, check the [SuperVoxel README](nnInteractive/supervoxel/README.md).
228
-
229
 
230
  ## Citation
231
  When using nnInteractive, please cite the following paper:
@@ -235,29 +78,8 @@ When using nnInteractive, please cite the following paper:
235
 
236
  Link: [![arXiv](https://img.shields.io/badge/arXiv-2503.08373-b31b1b.svg)](https://arxiv.org/abs/2503.08373)
237
 
238
-
239
  # License
240
- 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`!
241
-
242
- # Changelog
243
-
244
- ### 1.1.2 - 2025-08-02
245
-
246
- - Fixed a bug where `pin_memory` was set to `True` even though no CUDA devices were present (this broke CPU support)
247
- - ✅ API compatible all the way back to 1.0.1
248
-
249
- ### 1.1.1 - 2025-08-01
250
-
251
- - 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)
252
- - ✅ API compatible with 1.0.1 and 1.1.0
253
-
254
- ### 1.1.0 - 2025-08-01
255
-
256
- - Reworked inference code. It's now well-structured and easier to follow.
257
- - Fixed bugs that
258
- - sometimes caused blocky predictions
259
- - may cause failure to update segmentation map if changes were minor and AutoZoom was triggered
260
- - ✅ API compatible with 1.0.1
261
 
262
  ## Acknowledgments
263
 
@@ -268,4 +90,4 @@ Note that while this repository is available under Apache-2.0 license (see [LICE
268
 
269
  This repository is developed and maintained by the Applied Computer Vision Lab (ACVL)
270
  of [Helmholtz Imaging](https://www.helmholtz-imaging.de/) and the
271
- [Division of Medical Image Computing](https://www.dkfz.de/en/medical-image-computing) at DKFZ.
 
7
 
8
  # nnInteractive: Redefining 3D Promptable Segmentation
9
 
10
+ This repository hosts the official model checkpoints for `nnInteractive`, a state-of-the-art framework for 3D promptable segmentation.
 
 
 
11
 
12
+ > 📖 **Full documentation, installation, and usage live in the GitHub repository:**
13
+ > 👉 **[github.com/MIC-DKFZ/nnInteractive](https://github.com/MIC-DKFZ/nnInteractive)**
14
+ >
15
+ > Please refer to GitHub for the Python backend, installation instructions, code examples, the SuperVoxel module, and the changelog. This page only covers downloading the checkpoint.
16
 
17
+ `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 further integrations!
18
 
19
  <div align="center">
20
 
21
+ | **<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>** | **<div align="center">[OHIF integration](https://github.com/CCI-Bonn/OHIF-AI)</div>** |
22
+ |-------------------|----------------------|-------------------------|-------------------------|-------------------------|
23
+ | [<img src="imgs/Logos/napari.jpg" width="200">](https://github.com/MIC-DKFZ/napari-nninteractive) | [<img src="imgs/Logos/mitk.jpg" width="200">](https://www.mitk.org/wiki/MITK-nnInteractive) | [<img src="imgs/Logos/3DSlicer.png" width="200">](https://github.com/coendevente/SlicerNNInteractive) | [<img src="imgs/Logos/snaplogo_sq.png" width="200">](https://itksnap-dls.readthedocs.io/en/latest/quick_start.html) | [<img src="imgs/Logos/ohif.png" width="200">](https://github.com/CCI-Bonn/OHIF-AI) |
24
 
25
  </div>
26
 
 
 
 
 
 
 
 
 
 
27
  ---
28
 
 
29
  ## What is nnInteractive?
30
 
31
  > 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 \
 
33
 
34
  Link: [![arXiv](https://img.shields.io/badge/arXiv-2503.08373-b31b1b.svg)](https://arxiv.org/abs/2503.08373)
35
 
 
36
  ##### Abstract:
37
 
38
  Accurate and efficient 3D segmentation is essential for both clinical and research applications. While foundation
 
51
 
52
  <img src="imgs/figure1_method.png" width="1200">
53
 
54
+ ## Downloading the checkpoint
55
 
56
+ You normally don't need to download the weights manually — the napari, MITK, and other integrations, as well as the Python backend, fetch them for you. If you want the raw checkpoint, the snippet below pulls it from this repository:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  ```python
59
+ from huggingface_hub import snapshot_download # pip install huggingface_hub
 
 
 
60
 
 
61
  REPO_ID = "nnInteractive/nnInteractive"
62
  MODEL_NAME = "nnInteractive_v1.0" # Updated models may be available in the future
 
63
 
64
  download_path = snapshot_download(
65
  repo_id=REPO_ID,
66
  allow_patterns=[f"{MODEL_NAME}/*"],
 
67
  )
68
+ # The checkpoint is now in download_path/MODEL_NAME.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ```
70
 
71
+ For how to actually run inference with these weights, see the [GitHub README](https://github.com/MIC-DKFZ/nnInteractive).
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  ## Citation
74
  When using nnInteractive, please cite the following paper:
 
78
 
79
  Link: [![arXiv](https://img.shields.io/badge/arXiv-2503.08373-b31b1b.svg)](https://arxiv.org/abs/2503.08373)
80
 
 
81
  # License
82
+ The model checkpoint hosted in this repository is licensed under `Creative Commons Attribution Non Commercial Share Alike 4.0` (CC-BY-NC-SA-4.0); see [`nnInteractive_v1.0/LICENSE`](nnInteractive_v1.0/LICENSE). Note that the [Python backend code](https://github.com/MIC-DKFZ/nnInteractive) is released separately under the Apache-2.0 license.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  ## Acknowledgments
85
 
 
90
 
91
  This repository is developed and maintained by the Applied Computer Vision Lab (ACVL)
92
  of [Helmholtz Imaging](https://www.helmholtz-imaging.de/) and the
93
+ [Division of Medical Image Computing](https://www.dkfz.de/en/medical-image-computing) at DKFZ.
imgs/Logos/ohif.png ADDED