How to use nnunet
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- nnU-Net stands for 'no-new-Net', emphasizing its focus on robust configurations rather than novel architectures.
- It automatically adapts to different datasets and tasks, requiring minimal manual intervention.
- The framework supports 2D, 3D full resolution, and 3D cascade network architectures.
- nnU-Net achieved state-of-the-art results in several segmentation challenges.
- It is primarily used for medical image segmentation tasks in research and clinical settings.
What is nnU-Net?
nnU-Net, which stands for 'no-new-Net', is a powerful and highly successful framework for medical image segmentation. Developed by researchers at the German Cancer Research Center (DKFZ), its primary goal is to automate the process of configuring deep learning models for segmentation tasks. Instead of requiring users to design novel network architectures or meticulously tune hyperparameters for each new dataset, nnU-Net analyzes the dataset's properties and automatically determines the optimal network configuration, preprocessing steps, and training strategy. This 'out-of-the-box' approach has led to its widespread adoption and remarkable performance in various medical imaging challenges.
Why Use nnU-Net?
The complexity of medical image segmentation tasks often necessitates extensive experimentation with different model architectures, data augmentation techniques, and training parameters. This process can be time-consuming and requires significant expertise. nnU-Net significantly simplifies this workflow by providing a robust, automated solution. Its key advantages include:
- Automation: nnU-Net automates the entire pipeline, from data preprocessing to model training and inference, reducing manual effort and potential for human error.
- State-of-the-art Performance: It consistently achieves top performance in segmentation tasks, often outperforming custom-designed models, due to its rigorous self-configuration process.
- Versatility: The framework is designed to be general-purpose, adapting effectively to various imaging modalities (CT, MRI, etc.) and anatomical regions.
- Reproducibility: By automating the configuration, nnU-Net enhances the reproducibility of research findings.
How to Install nnU-Net
Installation is typically straightforward and can be done using pip. It's recommended to use a virtual environment to manage dependencies.
- Prerequisites: Ensure you have Python (3.7 or higher) and pip installed. CUDA-enabled GPU is highly recommended for efficient training.
- Installation Command: Open your terminal or command prompt and run:
pip install nnunet - Verification: After installation, you can verify it by running
nnUNet_print_configurationin your terminal.
Preparing Your Dataset for nnU-Net
nnU-Net expects datasets to be organized in a specific format. This ensures that the framework can correctly interpret and process your data.
Dataset Structure
A typical nnU-Net dataset consists of training and validation data, each with corresponding image and segmentation mask files. The dataset should be organized into folders named after the dataset, containing:
- imagesTr: Folder for training images.
- labelsTr: Folder for training segmentation masks.
- imagesTs: Folder for testing images (optional, for inference).
Each image file should be named in a specific pattern, such as datasetname_001.nii.gz, and its corresponding mask should be named datasetname_001.nii.gz. nnU-Net supports various medical imaging formats like NIfTI (.nii.gz).
Dataset Configuration File
nnU-Net requires a dataset configuration file (e.g., dataset.json) which describes the dataset's properties. This JSON file typically includes:
- description: A brief description of the dataset.
- modality: The imaging modality (e.g., 'CT', 'MRI').
- labels: A dictionary mapping integer labels to their names (e.g., {'1': 'tumor', '2': 'organ'}).
- num_classes: The total number of segmentation classes.
- train: List of training image file names.
- val: List of validation image file names.
This file is crucial for nnU-Net to understand the structure and content of your data.
Using nnU-Net for Training
Once your dataset is prepared and configured, you can initiate the training process using nnU-Net's command-line interface.
Steps for Training
- Run the training command: The primary command is
nnUNet_train. You need to specify the network topology (e.g., 2d, 3dfullres, 3dlowres, 3dcascade), the dataset ID, and optionally the GPU ID. For example:nnUNet_train 2d dataset_id 0(for 2D training on GPU 0)nnUNet_train 3dfullres dataset_id 0(for 3D full-resolution training on GPU 0) - Automatic Configuration: nnU-Net will automatically analyze your dataset, determine the best network architecture, apply appropriate preprocessing, and start the training.
- Output: The trained models and training logs will be saved in the
nnUNet_resultsdirectory.
Network Architectures
nnU-Net automatically selects from three main network configurations:
- 2D U-Net: Processes images slice by slice.
- 3D U-Net (full resolution): Processes the entire 3D volume at its original resolution.
- 3D U-Net (low resolution cascade): Uses a cascade of networks, starting with a lower-resolution volume and refining predictions with higher-resolution stages.
The choice depends on the dataset's characteristics, such as image resolution and size.
Using nnU-Net for Inference
After training, you can use the trained model to predict segmentation masks on new, unseen images.
Steps for Inference
- Run the inference command: Use the
nnUNet_predictcommand, specifying the trained model folder (usually found innnUNet_results), the input image path, and the output path for the segmentation mask. For example:nnUNet_predict -i /path/to/your/input/image.nii.gz -o /path/to/your/output/mask.nii.gz -tr nnUNet_results/my_trained_model_folder - Batch Inference: You can also predict on entire folders of images.
Customization and Advanced Usage
While nnU-Net excels at automation, it also offers options for customization for advanced users:
- Configuration Files: Users can modify configuration files to fine-tune parameters like learning rates, batch sizes, and data augmentation strategies.
- Cross-validation: nnU-Net supports k-fold cross-validation for more robust model evaluation.
- Integration: The framework can be integrated into larger medical imaging pipelines.
nnU-Net represents a significant advancement in automated medical image segmentation, making powerful deep learning tools more accessible to researchers and clinicians.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
Missing an answer?
Suggest a question and we'll generate an answer for it.