File size: 2,099 Bytes
de4717a
 
bb8c6c9
 
 
 
 
 
 
de4717a
bb8c6c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
license: cc-by-4.0
library_name: pytorch
pipeline_tag: image-segmentation
tags:
  - retinal-vessel-segmentation
  - artery-vein-classification
  - medical-imaging
  - fundus-photography
---

# R2-V2 (bv)

Weights for the `bv` variant of **R2-V2**, the winning method of the
**Generalized Analysis of Vessels in Eye (GAVE) Challenge at MICCAI 2025**,
for blood vessel segmentation and artery/vein classification in retinal
fundus images.

R2-V2 is based on the [RRWNet](https://github.com/j-morano/rrwnet) architecture.

The `bv` model is more balanced than the `av` variant, and performs
particularly well for vessel segmentation.

This repo is meant for **easy inference**: it bundles the `bv` weights
together with the (unmodified except for `.safetensors` loading support) code
needed to run them, so it works standalone without cloning anything else.
For the full training/reproducibility code, see the
[R2-V2 GitHub repo](https://github.com/j-morano/R2-V2).

## Files

- `bv.safetensors`: model weights (RRWNet state dict).
- `bv_config.json`: configuration used to produce these weights.
- `model.py`, `infer.py`, `preprocessing.py`, `transformations.py`: inference
  pipeline code (image preprocessing, artery/vein post-processing, CLI).
- `requirements.txt`: pinned dependencies (Python 3.12.8, PyTorch 2.8, CUDA 12.8).

## Usage

```sh
python -m venv venv/ && source venv/bin/activate
pip install -r requirements.txt

python infer.py -i <path_to_images> -t bv -w . -s <output_path>
```

`-w .` tells `infer.py` to look for `bv.safetensors` and `bv_config.json` in
the current directory. Run `python infer.py -h` for all options (test-time
augmentation, masks, GAVE output format, etc.).

To load the weights manually instead:

```python
import json
from safetensors.torch import load_model
from model import RRWNet

config = json.load(open("bv_config.json"))
model = RRWNet(
    input_ch=config["in_channels"],
    output_ch=config["out_channels"],
    base_ch=config["base_channels"],
    num_iterations=config["num_iterations"],
)
load_model(model, "bv.safetensors")
model.eval()
```