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

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

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]"

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, 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.

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.0.tar.gz (21.9 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.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for segmentation_quality_control-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bdd98ac986c4df67a9b1a857c9b2182557a41a5950fcd235f3b840b484ba71aa
MD5 87a331d1165b85e0d2c46189330fa1e3
BLAKE2b-256 ca27d5a77662ef1c29f6f6a14df80ea82d9a264c26e18f254af012c9d9c84219

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmentation_quality_control-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for segmentation_quality_control-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 677c0e1906eebfa4b93518b80834d557f8377569963e8c520ae071e9db8cc55c
MD5 275c82f0e18cd9691c2b7556b298cb5f
BLAKE2b-256 af2d99fa5df0843776b15f1169111e0a4598ccfff72a3416aa6e2a1a94474530

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmentation_quality_control-0.1.0-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