Upload weights/README.md with huggingface_hub
Browse files- weights/README.md +82 -0
weights/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# RetRep — Retinal Foundation Models Repository
|
| 2 |
+
|
| 3 |
+
A unified Python package for retinal/ophthalmology foundation models with a timm-compatible API.
|
| 4 |
+
Create, extract features, and fine-tune 16+ pretrained vision models for fundus, OCT, and retinal image analysis.
|
| 5 |
+
|
| 6 |
+
## Quick Start
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
import torch
|
| 10 |
+
from retrep import create_model, list_models
|
| 11 |
+
|
| 12 |
+
# List all available models
|
| 13 |
+
print(list_models())
|
| 14 |
+
|
| 15 |
+
# Feature extraction with RETFound (auto-downloads weights from HuggingFace)
|
| 16 |
+
model = create_model('retfound_dinov2_meh', pretrained=True, hf_token='YOUR_HF_TOKEN')
|
| 17 |
+
features = model(torch.randn(1, 3, 518, 518))
|
| 18 |
+
print(features.shape) # torch.Size([1, 1024])
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Weight Auto-Download
|
| 22 |
+
|
| 23 |
+
RetRep automatically downloads model weights from HuggingFace Hub when needed:
|
| 24 |
+
|
| 25 |
+
1. **Local `weights/` directory** — checked first (for development)
|
| 26 |
+
2. **HF cache** (`~/.cache/retrep/weights/`) — checked second
|
| 27 |
+
3. **HuggingFace Hub** — auto-downloaded if not found locally
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
from retrep import get_weight_path
|
| 31 |
+
|
| 32 |
+
# Get weight path (auto-downloads if needed)
|
| 33 |
+
path = get_weight_path("retfound_dinov2_meh")
|
| 34 |
+
print(path) # /home/user/.cache/retrep/weights/retfound_dinov2_meh.pth
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Model Registry
|
| 38 |
+
|
| 39 |
+
| Model Name | Type | Backbone | Input Size | Output Dim | Weight Source |
|
| 40 |
+
|---|---|---|---|---|---|
|
| 41 |
+
| `retfound_mae_natureCFP` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_natureCFP) (gated) |
|
| 42 |
+
| `retfound_mae_natureOCT` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_natureOCT) (gated) |
|
| 43 |
+
| `retfound_mae_meh` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_meh) (gated) |
|
| 44 |
+
| `retfound_mae_shanghai` | MAE | ViT-L/16 | 224x224 | 1024 | [HF](https://huggingface.co/YukunZhou/RETFound_mae_shanghai) (gated) |
|
| 45 |
+
| `retfound_dinov2_meh` | DINOv2 | ViT-L/14 | 518x518 | 1024 | Auto-download from HF |
|
| 46 |
+
| `retfound_dinov2_shanghai` | DINOv2 | ViT-L/14 | 518x518 | 1024 | Auto-download from HF |
|
| 47 |
+
| `urfound` | MAE | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
|
| 48 |
+
| `flair` | CLIP | SigLIP-B/16 | 224x224 | 512 | Auto-download from HF |
|
| 49 |
+
| `eyeclip` | CLIP | ViT-B/32 | 224x224 | 768 | Auto-download from HF |
|
| 50 |
+
| `ret_clip` | CLIP | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
|
| 51 |
+
| `vision_fm` | Self-supervised | ViT-B/16 | 224x224 | 768 | Auto-download from HF |
|
| 52 |
+
| `eyecare_gpt` | SigLIP | SigLIP-So400m | 384x384 | 1152 | Auto-download from HF |
|
| 53 |
+
| `reti_zero` | CLIP+LoRA | ViT-L/16 | 224x224 | 512 | Auto-download from HF |
|
| 54 |
+
| `keepfit` | CLIP | ResNet-50 | 512x512 | 512 | Auto-download from HF |
|
| 55 |
+
| `vision_unite` | Multimodal | EVA02-B/14 + CLIP | 224x224 | 768 | Auto-download from HF |
|
| 56 |
+
| `deepdr_llm` | Multimodal | ViT-B/16 | 224x224 | 768 | No pretrained weights |
|
| 57 |
+
|
| 58 |
+
## Installation
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
pip install -e .
|
| 62 |
+
|
| 63 |
+
# Optional: for CLIP-style models (EyeCLIP, FLAIR, RET-CLIP)
|
| 64 |
+
pip install -e ".[clip]"
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Uploading Weights to HuggingFace
|
| 68 |
+
|
| 69 |
+
```bash
|
| 70 |
+
# Set your HF token
|
| 71 |
+
export HF_TOKEN=hf_xxxxx
|
| 72 |
+
|
| 73 |
+
# Upload all weights
|
| 74 |
+
python scripts/upload_weights_to_hf.py
|
| 75 |
+
|
| 76 |
+
# Upload a single file
|
| 77 |
+
python scripts/upload_weights_to_hf.py --file retfound_dinov2_meh.pth
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## License
|
| 81 |
+
|
| 82 |
+
MIT — see [LICENSE](../LICENSE)
|