File size: 3,217 Bytes
30bca61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# RetRep — Retinal Foundation Models Repository

A unified Python package for retinal/ophthalmology foundation models with a timm-compatible API.
Create, extract features, and fine-tune 16+ pretrained vision models for fundus, OCT, and retinal image analysis.

## Quick Start

```python
import torch
from retrep import create_model, list_models

# List all available models
print(list_models())

# Feature extraction with RETFound (auto-downloads weights from HuggingFace)
model = create_model('retfound_dinov2_meh', pretrained=True, hf_token='YOUR_HF_TOKEN')
features = model(torch.randn(1, 3, 518, 518))
print(features.shape)  # torch.Size([1, 1024])
```

## Weight Auto-Download

RetRep automatically downloads model weights from HuggingFace Hub when needed:

1. **Local `weights/` directory** — checked first (for development)
2. **HF cache** (`~/.cache/retrep/weights/`) — checked second
3. **HuggingFace Hub** — auto-downloaded if not found locally

```python
from retrep import get_weight_path

# Get weight path (auto-downloads if needed)
path = get_weight_path("retfound_dinov2_meh")
print(path)  # /home/user/.cache/retrep/weights/retfound_dinov2_meh.pth
```

## Model Registry

| Model Name | Type | Backbone | Input Size | Output Dim | Weight Source |
|---|---|---|---|---|---|
| `retfound_mae_natureCFP` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_natureCFP) (gated) |
| `retfound_mae_natureOCT` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_natureOCT) (gated) |
| `retfound_mae_meh` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_meh) (gated) |
| `retfound_mae_shanghai` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_shanghai) (gated) |
| `retfound_dinov2_meh` | DINOv2 | ViT-L/14 | 518x518 | 1024 | Auto-download from HF |
| `retfound_dinov2_shanghai` | DINOv2 | ViT-L/14 | 518x518 | 1024 | Auto-download from HF |
| `urfound` | MAE | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
| `flair` | CLIP | SigLIP-B/16 | 224x224 | 512 | Auto-download from HF |
| `eyeclip` | CLIP | ViT-B/32 | 224x224 | 768 | Auto-download from HF |
| `ret_clip` | CLIP | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
| `vision_fm` | Self-supervised | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
| `eyecare_gpt` | SigLIP | SigLIP-So400m | 384x384 | 1152 | Auto-download from HF |
| `reti_zero` | CLIP+LoRA | ViT-L/16 | 224x224 | 512 | Auto-download from HF |
| `keepfit` | CLIP | ResNet-50 | 512x512 | 512 | Auto-download from HF |
| `vision_unite` | Multimodal | EVA02-B/14 + CLIP | 224x224 | 768 | Auto-download from HF |
| `deepdr_llm` | Multimodal | ViT-B/16 | 224x224 | 768 | No pretrained weights |

## Installation

```bash
pip install -e .

# Optional: for CLIP-style models (EyeCLIP, FLAIR, RET-CLIP)
pip install -e ".[clip]"
```

## Uploading Weights to HuggingFace

```bash
# Set your HF token
export HF_TOKEN=hf_xxxxx

# Upload all weights
python scripts/upload_weights_to_hf.py

# Upload a single file
python scripts/upload_weights_to_hf.py --file retfound_dinov2_meh.pth
```

## License

MIT — see [LICENSE](../LICENSE)