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

Quick Answer: nnU-Net is a self-configuring framework for medical image segmentation that automates the selection of optimal network architecture, preprocessing, and training parameters. To use it, you typically install it, prepare your dataset in a specific format, and then run the training and inference commands via its command-line interface.

Key Facts

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:

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.

  1. Prerequisites: Ensure you have Python (3.7 or higher) and pip installed. CUDA-enabled GPU is highly recommended for efficient training.
  2. Installation Command: Open your terminal or command prompt and run:
    pip install nnunet
  3. Verification: After installation, you can verify it by running nnUNet_print_configuration in 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:

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:

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

  1. 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)
  2. Automatic Configuration: nnU-Net will automatically analyze your dataset, determine the best network architecture, apply appropriate preprocessing, and start the training.
  3. Output: The trained models and training logs will be saved in the nnUNet_results directory.

Network Architectures

nnU-Net automatically selects from three main network configurations:

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

  1. Run the inference command: Use the nnUNet_predict command, specifying the trained model folder (usually found in nnUNet_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
  2. 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:

nnU-Net represents a significant advancement in automated medical image segmentation, making powerful deep learning tools more accessible to researchers and clinicians.

Sources

  1. nnU-Net GitHub RepositoryApache-2.0
  2. nnU-Net: a self-configuring framework for convolutional neural networks for medical image segmentationCC-BY-4.0
  3. nnU-Net: Self-adapting General Purpose Deep Learning for Medical Image SegmentationarXiv - Open Access

Missing an answer?

Suggest a question and we'll generate an answer for it.