Skip to main content

MIDL 2024 paper: Efficiently correcting patch-based segmentation errors to control image-level performance in retinal images

Project description

Efficiently correcting patch-based segmentation errors to control image-level performance

Experiments for MIDL 2024 paper.

Installation

Requires Python >= 3.9

Development setup with uv (recommended)

Clone the repository:

git clone https://github.com/berenslab/MIDL24-segmentation_quality_control.git
cd MIDL24-segmentation_quality_control
uv sync --extra dev
source .venv/bin/activate  # Windows: .venv\Scripts\activate

Development setup without uv

Alternatively, use Python's built-in venv:

git clone https://github.com/berenslab/MIDL24-segmentation_quality_control.git
cd MIDL24-segmentation_quality_control
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e ".[dev]"

From PyPI (recommended for use as a dependency)

Install the released package:

pip install segmentation_quality_control

PyPI wheels include the Python code only. Ensemble checkpoints (~360 MB) are not bundled; see Model weights below.

From GitHub (development version)

Install the latest development version without cloning:

pip install git+https://github.com/berenslab/MIDL24-segmentation_quality_control

Model weights

The FR-UNet ensemble uses five checkpoints: FRUNet_0.pth, ..., FRUNet_4.pth.

Where weights are resolved

When loading models, the package resolves the checkpoint directory in this order:

  1. Custom path: pass models_dir=... to ensure_models_dir().
  2. Local development checkout: if all five files are present in the repository's trained/ folder, that directory is used. This applies to editable installs (pip install -e .) and cloned repositories.
  3. User cache (OS default for PyPI and other installs):
OS Default cache directory
Linux ~/.cache/segmentation_quality_control/trained/
macOS ~/Library/Caches/segmentation_quality_control/trained/
Windows %LOCALAPPDATA%\segmentation_quality_control\trained\

Automatic download

If weights are missing from the resolved location (such as when using as a pypi dependency), they are downloaded over HTTPS from GitHub (trained/) into the cache directory:

from segmentation_quality_control.utils import ensure_models_dir

models_dir = ensure_models_dir()  # downloads on first call if needed

If Python's https-download mechanism fails, the package falls back to using git when it is available on PATH.

Manual download

If the automatic download fails, fetch the files directly:

mkdir -p ~/.cache/segmentation_quality_control/trained
wget -O ~/.cache/segmentation_quality_control/trained/FRUNet_0.pth \
  https://raw.githubusercontent.com/berenslab/MIDL24-segmentation_quality_control/main/trained/FRUNet_0.pth
# repeat for FRUNet_1.pth … FRUNet_4.pth, or use curl -L -o ...

Alternatively, use a sparse git checkout:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/berenslab/MIDL24-segmentation_quality_control.git \
  ~/tmp/segmentation_weights
cd ~/tmp/segmentation_weights
git sparse-checkout set trained
git checkout main
# then copy trained/FRUNet_*.pth into your cache or repo trained/ directory

Checkpoint format

  • Weights are plain PyTorch checkpoints (not bundled in PyPI wheels).
  • Keys: arch, epoch, state_dict, optimizer, config
  • Loading no longer requires the legacy bunch package.
  • To save new checkpoints after retraining, use segmentation_quality_control.utils.checkpoint.save_checkpoint, to store them in the bunch-less format.

Reproduce the paper results

Instructions to reproduce the experiments (development setup):

  1. Install the package as above (uv sync --extra dev or pip install -e ".[dev]").
  2. Download the FIVES dataset (Jin et al., 2022) and register its path in paths.yaml.
  3. Execute 0_pass_forward.ipynb to pass the data through the ensemble and log the outputs. In a cloned repository, weights are read from trained/.
  4. Calibrate with temperature scaling on the validation set with 1_calibrate.ipynb.
  5. Compute $\widehat{DSC}$ and $\widehat{DSC}_{\text{corr}}$ in 2_estimate_DSC.ipynb.
  6. Reproduce figures with the respective scripts.

References

Jin, Kai, et al. "Fives: A fundus image dataset for artificial Intelligence based vessel segmentation." Scientific Data 9.1 (2022): 475.

Paper and Citation

The paper (MIDL 2024 oral):

  • Köhler et al., Efficiently correcting patch-based segmentation errors to control image-level performance in retinal images (2024)
  • PDF at OpenReview

Citation:

@inproceedings{
koehler2024efficiently,
title={Efficiently correcting patch-based segmentation errors to control image-level performance in retinal images},
author={Patrick K{\"o}hler and Jeremiah Fadugba and Philipp Berens and Lisa M. Koch},
booktitle={Medical Imaging with Deep Learning},
year={2024},
url={https://openreview.net/forum?id=DDHRGHfwji}
}

Note

This package has been bundled into the Fundus Image Toolbox for convenient application next to other useful retinal fundus imaging tools.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segmentation_quality_control-0.1.1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segmentation_quality_control-0.1.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file segmentation_quality_control-0.1.1.tar.gz.

File metadata

File hashes

Hashes for segmentation_quality_control-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff4fe167ed0e5c6788fadfbc60975718e0dcac19bb15707549adeda320bd30dd
MD5 e9614674554f8f433769679ce5a4adec
BLAKE2b-256 298f7da16391d15daa304684bc8058572b324cfb786ce17383e786364a06a26a

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmentation_quality_control-0.1.1.tar.gz:

Publisher: python-publish.yml on berenslab/MIDL24-segmentation_quality_control

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file segmentation_quality_control-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for segmentation_quality_control-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3613705cae087b71fc6d454d705336d88e966b4a5393fcfc8a680a29337a6867
MD5 68ba59ad452fbf8c579243f4cc08accc
BLAKE2b-256 3d5c461df476c6276f78ea64934b0e5c6b90292da566707432fee80a08d67e37

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmentation_quality_control-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on berenslab/MIDL24-segmentation_quality_control

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page