File size: 4,474 Bytes
e025b68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
tags:
  - vision
  - dinov2
  - hematology
  - cytomorphology
  - foundation-model
license: apache-2.0
citation: |
  @inproceedings{koch2024dinobloom,
    title={DinoBloom: a foundation model for generalizable cell embeddings in hematology},
    author={Koch, Valentin and Wagner, Sophia J and Kazeminia, Salome and Sancar, Ece and Hehr, Matthias and Schnabel, Julia A and Peng, Tingying and Marr, Carsten},
    booktitle={International Conference on Medical Image Computing and Computer-Assisted Intervention},
    pages={520--530},
    year={2024},
    organization={Springer}
  }
---

# DinoBloom: A Foundation Model for Generalizable Cell Embeddings in Hematology

<div align="center">
  <img src="https://raw.githubusercontent.com/MarrLab/DinoBloom/main/media/logo.png" width="160" alt="DinoBloom logo"/>
  <br><br>

  **DinoBloom** builds upon [DINOv2](https://arxiv.org/abs/2304.07193) (Meta AI) and is trained on **13 diverse publicly available datasets** of single cells from peripheral blood and bone marrow.

  <br>
  <a href="https://arxiv.org/abs/2404.05022">πŸ“„ Paper</a> β€’
  <a href="https://github.com/MarrLab/DinoBloom">πŸ’» GitHub</a> β€’
  <a href="https://zenodo.org/records/10908163">πŸ“¦ Zenodo</a>
</div>

---

## 🧠 Model Variants

DinoBloom is available in **four sizes**:

| Model | Feature Dim | Parameters | Checkpoint |
|-------|-------------|------------|------------|
| **DinoBloom-S** | 384 | 22M | `pytorch_model_s.bin` |
| **DinoBloom-B** | 768 | 86M | `pytorch_model_b.bin` |
| **DinoBloom-L** | 1024 | 304M | `pytorch_model_l.bin` |
| **DinoBloom-G** | 1536 | 1136M | `pytorch_model_g.bin` |

---

## πŸš€ Usage

```python
from huggingface_hub import hf_hub_download
import torch
import torch.nn as nn

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Choose variant: "s", "b", "l", or "g"
variant = "b"

# Configuration
variant_config = {
    "s": ("dinov2_vits14", 384),
    "b": ("dinov2_vitb14", 768),
    "l": ("dinov2_vitl14", 1024),
    "g": ("dinov2_vitg14", 1536),
}

dinov2_model, embed_dim = variant_config[variant]

# Load base DINOv2 model
model = torch.hub.load("facebookresearch/dinov2", dinov2_model)

# Download DinoBloom weights
ckpt_path = hf_hub_download(
    repo_id="MarrLab/DinoBloom",
    filename=f"pytorch_model_{variant}.bin"
)
ckpt = torch.load(ckpt_path, map_location="cpu")

num_tokens = int(1 + (224 / 14) ** 2)
model.pos_embed = nn.Parameter(torch.zeros(1, num_tokens, embed_dim))
model.load_state_dict(ckpt, strict=True)
model.to(device)
model.eval()

# Get transforms
from torchvision import transforms
transform = transforms.Compose([
    transforms.Resize((224,224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

# Apply to image
from PIL import Image
img = Image.open("path/to/cell_image")
img_tensor = transform(img).unsqueeze(0).to(device)

# Get features
with torch.no_grad():
    features = model(img_tensor)

print(f"Features shape: {features.shape}")  # [1, 768] for DinoBloom-B
```

---

## πŸ“Š Model Performance

DinoBloom outperforms existing medical and non-medical vision models in:

1. **Linear probing** and **k-nearest neighbor** evaluations for cell-type classification
2. **Weakly supervised multiple-instance learning (MIL)** for acute myeloid leukemia subtyping

See our [paper](https://arxiv.org/abs/2404.05022) for detailed benchmarks.

---

## πŸ”§ Requirements

```bash
pip install torch torchvision huggingface_hub
```

---

## πŸ“š Citation

If you use DinoBloom in your research, please cite:

```bibtex
@inproceedings{koch2024dinobloom,
  title={DinoBloom: a foundation model for generalizable cell embeddings in hematology},
  author={Koch, Valentin and Wagner, Sophia J and Kazeminia, Salome and Sancar, Ece and Hehr, Matthias and Schnabel, Julia A and Peng, Tingying and Marr, Carsten},
  booktitle={International Conference on Medical Image Computing and Computer-Assisted Intervention},
  pages={520--530},
  year={2024},
  organization={Springer}
}
```

---

## πŸ“– Related Work

DinoBloom builds upon:
- [DINOv2](https://arxiv.org/abs/2304.07193) - Self-supervised vision transformers
- [Original DinoBloom Paper](https://arxiv.org/abs/2404.05022) - MICCAI 2024

---

## πŸ“„ License

Apache 2.0 - See [LICENSE](LICENSE) file for details.

---


For questions or issues, please open an issue on [GitHub](https://github.com/MarrLab/DinoBloom) or contact the authors.