Transformers
ONNX
Safetensors
swinv2_segmenter
retinal-fundus
artery-vein-segmentation
medical-imaging
ophthalmology
swinv2
custom_code
Instructions to use JonathanFhima/RLAD-SwinV2-Large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JonathanFhima/RLAD-SwinV2-Large with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("JonathanFhima/RLAD-SwinV2-Large", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Drop the image-segmentation tag too - HF was inferring pipeline_tag back from it, which drove the misleading pipeline() snippet and task-specific Colab/Kaggle notebook templates (both assume single-label argmax output, which this multi-label model does not produce). artery-vein-segmentation tag already covers discoverability.
cf1f116 verified |
Download README.md from JonathanFhima/RLAD-SwinV2-Large: direct link, hf CLI and curl.
- Browser
- Download file 6.25 kB
-
https://huggingface.co/JonathanFhima/RLAD-SwinV2-Large/resolve/main/README.md
- Command line
-
hf download hf://JonathanFhima/RLAD-SwinV2-Large/README.md
-
curl -L -o README.md https://huggingface.co/JonathanFhima/RLAD-SwinV2-Large/resolve/main/README.md
6.25 kB
| pretty_name: "RLAD + SwinV2-Large (aka LUNetV2): Retinal Artery/Vein Segmentation" | |
| license: other | |
| license_name: apache-2.0-code-plus-noncommercial-weights | |
| library_name: transformers | |
| base_model: microsoft/swinv2-large-patch4-window12-192-22k | |
| tags: | |
| - retinal-fundus | |
| - artery-vein-segmentation | |
| - medical-imaging | |
| - ophthalmology | |
| - swinv2 | |
| datasets: | |
| - JonathanFhima/REYIA | |
| # Enhancing Retinal Vessel Segmentation Generalization via Layout-Aware Generative Modelling | |
| ### State-of-the-art AV segmentation in retinal fundus images | |
| <div align="center"> | |
| Jonathan Fhima β’ Jan Van Eijgen β’ Lennert Beeckmans β’ Thomas Jacob β’ Moti Freiman | |
| <br> | |
| Luis Filipe Nakayama β’ Ingeborg Stalmans β’ Chaim Baskin β’ Joachim A. Behar | |
| </div> | |
| [](https://arxiv.org/abs/2503.01190) | |
| [](https://github.com/aim-lab/RLAD) | |
| [](https://huggingface.co/datasets/JonathanFhima/REYIA) | |
| [](https://colab.research.google.com/github/aim-lab/PVBM/blob/main/rlad_pvbm_tutorial.ipynb) | |
| The strongest open-weight model for retinal artery/vein segmentation we know of, trained with [RLAD](https://github.com/aim-lab/RLAD)-generated images and the [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) dataset. Internally also known as LUNetV2. | |
|  | |
| ## Quickstart | |
| The model loads the standard Hugging Face way - `AutoModel` and | |
| `AutoImageProcessor` with `trust_remote_code=True` download the code, config, | |
| weights, and preprocessing directly, nothing to fetch by hand: | |
| ```python | |
| import numpy as np | |
| import torch | |
| from PIL import Image | |
| from transformers import AutoModel, AutoImageProcessor | |
| repo = "JonathanFhima/RLAD-SwinV2-Large" | |
| model = AutoModel.from_pretrained(repo, trust_remote_code=True).to("cuda").to(torch.bfloat16).eval() | |
| processor = AutoImageProcessor.from_pretrained(repo, trust_remote_code=True) | |
| image = Image.open("fundus.png").convert("RGB") | |
| inputs = processor(image, return_tensors="pt")["pixel_values"].to("cuda", torch.bfloat16) | |
| with torch.no_grad(): | |
| output = model(inputs).float() | |
| probs = torch.sigmoid(output)[0].cpu().numpy() | |
| mask = np.zeros((*probs.shape[1:], 3), dtype=np.uint8) | |
| mask[probs[0] > 0.5, 0] = 255 # arteries: red | |
| mask[(probs[1] > 0.5) & ~(probs[0] > 0.5), 2] = 255 # veins: blue | |
| ``` | |
| Or just run the CLI script, which does the same thing plus writes a blended | |
| overlay image: | |
| ```bash | |
| python3 -m venv lunetv2_env && source lunetv2_env/bin/activate | |
| pip install -r requirements.txt | |
| python infer.py fundus.png out/ | |
| ``` | |
| Writes `out/mask.png` and `out/overlay.png`. Runs in `bfloat16`, the | |
| precision the model was trained in. | |
| For a full pipeline from a raw fundus image to vasculature biomarkers, see the | |
| [RLAD + PVBM end-to-end tutorial](https://colab.research.google.com/github/aim-lab/PVBM/blob/main/rlad_pvbm_tutorial.ipynb), | |
| which feeds this model's output into [PVBM](https://github.com/aim-lab/PVBM). | |
| ## Example | |
|  | |
| ## Results | |
| If you plan to use this model or compare against it, we recommend | |
| scoring against our benchmark rather than re-running every baseline | |
| yourself. The scorer that produced these numbers lives in the | |
| [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) repo | |
| (`scripts/eval/dice_score.py`). | |
| Artery/vein Dice score, averaged across the same local, external, and out-of-distribution (OOD) test sets; β rows show the improvement RLAD adds on top of each backbone, and β marks results with data leakage during training β this release is the SwinV2-large row. | |
|  | |
| ## Ablations | |
|  | |
|  | |
| ## License | |
| The code (`LUNetv2.py`, `infer.py`) is Apache 2.0. The weights | |
| (`model.safetensors`) are non-commercial, research use only β the | |
| training set mixes in subsets that are themselves non-commercial or | |
| restricted: | |
| | Source | Status | | |
| |---|---| | |
| | UZLF | [KU Leuven dataset](https://rdr.kuleuven.be/dataset.xhtml?persistentId=doi:10.48804/Z7SHGO) | | |
| | GRAPE | CC0 1.0 β see [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) | | |
| | MAGRABIA | CC BY-NC 4.0 β see [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) | | |
| | MESSIDOR | redistribution and commercial use explicitly prohibited β see [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) | | |
| | PAPILA | figshare license field reads GPL 3.0+ β likely a depositor mis-click, not corrected as of this writing β see [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) | | |
| | ENRICH | non-commercial use only, KU Leuven data-sharing protocol β see [REYIA](https://huggingface.co/datasets/JonathanFhima/REYIA) | | |
| ## Citation | |
| > Fhima, J., Van Eijgen, J., Beeckmans, L., Jacob, T., Freiman, M., | |
| > Nakayama, L.F., Stalmans, I., Baskin, C., Behar, J.A. *Enhancing Retinal | |
| > Vessel Segmentation Generalization via Layout-Aware Generative | |
| > Modelling.* arXiv:2503.01190, 2025. https://arxiv.org/abs/2503.01190 | |