# nnU-Net

> Self-configuring deep learning for biomedical image segmentation

- Category: Science & Biomedical AI / Medical Imaging
- Language: Python
- Repository: https://github.com/MIC-DKFZ/nnUNet
- Canonical page: https://ai-tldr.dev/tools/nnunet/

## In short

nnU-Net is a semantic segmentation framework that automatically adapts its pipeline to a dataset. It analyzes the training data, creates a dataset fingerprint, and configures suitable U-Net variants without you having to tune the setup by hand. It sits in the Medical Imaging category of the Science & Biomedical AI tools and is open-source, written in Python.

## Overview

nnU-Net is a semantic segmentation framework that automatically adapts its pipeline to a dataset. It analyzes the training data, creates a dataset fingerprint, and configures suitable U-Net variants without you having to tune the setup by hand.

It is aimed at biomedical image segmentation and works with both 2D and 3D data, arbitrary channel definitions, and multiple image formats. The framework runs end to end, from preprocessing through training to inference, and is designed to train models from scratch on a new dataset.

nnU-Net is developed by the Applied Computer Vision Lab at Helmholtz Imaging and the Division of Medical Image Computing at DKFZ. It is released under the Apache-2.0 license, and the authors ask that work using it cite the 2021 Nature Methods paper by Isensee et al.

## What it does

- Automatically adapts its preprocessing, network, and training pipeline to a dataset
- Analyzes training data and creates a dataset fingerprint to configure U-Net variants
- Supports both 2D and 3D data with arbitrary channel definitions
- Works with multiple image formats and runs end to end from preprocessing to inference
- Offers multiple U-Net configurations: 2d, 3d_fullres, 3d_lowres, and 3d_cascade_fullres
- Includes tools to find the best configuration, ensemble predictions, and apply postprocessing

## Getting started

Install nnU-Net, set its three data path variables, then plan, train, and predict from the command line.

1. Install nnU-Net

   Install the v2 package with pip.

```bash
pip install nnunetv2
```

2. Set the data path variables

   nnU-Net reads three environment variables that point to your raw data, preprocessed data, and results folders.

```bash
export nnUNet_raw="/path/to/nnUNet_raw"
export nnUNet_preprocessed="/path/to/nnUNet_preprocessed"
export nnUNet_results="/path/to/nnUNet_results"
```

3. Plan and preprocess a dataset

   Analyze the dataset and prepare it for training. The integrity check helps catch problems before training starts.

```bash
nnUNetv2_plan_and_preprocess -d DATASET_ID --verify_dataset_integrity
```

4. Train a model

   Train a configuration on a fold. Configuration is one of 2d, 3d_fullres, 3d_lowres, or 3d_cascade_fullres, and FOLD is a value from 0 to 4.

```bash
nnUNetv2_train DATASET_NAME_OR_ID UNET_CONFIGURATION FOLD
```

5. Run inference on new images

   Predict segmentations for a folder of input images using a trained configuration.

```bash
nnUNetv2_predict -i INPUT_FOLDER -o OUTPUT_FOLDER -d DATASET_NAME_OR_ID -c CONFIGURATION
```

## When to use it

- Segment organs, lesions, or other structures in 2D or 3D biomedical scans
- Train a segmentation model from scratch on a new dataset without manual pipeline tuning
- Compare 2d, 3d_fullres, 3d_lowres, and 3d_cascade_fullres configurations and pick the best one
- Ensemble multiple models and apply postprocessing to produce final segmentations
