MOSAIC / README.md
Astaxanthin's picture
Update README.md
75e5626 verified
|
Raw History Blame Contribute Delete
2.49 kB
---
library_name: transformers
language:
- en
tags:
- computational-pathology
- multimodal
- survival-analysis
- feature-extraction
- custom_code
---
# MOSAIC
MOSAIC integrates histopathology, clinical information, and genomics for survival prediction. It accepts WSI patch features, clinical data, and/or SNV/CNV gene lists, and returns **OS and PFS risk scores**. When WSI features are provided, it also returns a **768-dimensional WSI embedding**.
For data preparation, treatment-response evaluation, prognosis-prediction and further documentation, see **[MAGIC-AI4Med/MOSAIC on GitHub](https://github.com/MAGIC-AI4Med/MOSAIC)**.
## Installation
```bash
pip install "torch>=2.6" "transformers==4.57.1" "nystrom-attention==0.0.14" "safetensors>=0.4" "numpy>=1.26" h5py
```
## Usage
WSI patch features should be extracted using [KEEP](https://huggingface.co/Astaxanthin/KEEP).
```python
import h5py
import torch
from transformers import AutoModel
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModel.from_pretrained(
"Astaxanthin/MOSAIC", trust_remote_code=True,
).to(device).eval()
# One slide: KEEP patch features and matching spatial coordinates.
with h5py.File("slide_features.h5", "r") as f:
features = f["features"][:] # [N, 768]
coords = f["coords"][:] # [N, 2]
output = model.predict(
patch_features=features,
patch_coords=coords,
cancer_type="Lung Adenocarcinoma",
clinical={"age": 65, "sex": "Male", "stage": "II"},
genomics={"snv": ["TP53"], "cnv": ["CDKN2A"]},
)
print("WSI embedding:", output["wsi_features"].shape) # [1, 768]
print("OS risk:", output["os_risk"].item())
print("PFS risk:", output["pfs_risk"].item())
# Clinical-only inference: omit WSI and genomic inputs.
clinical_output = model.predict(
cancer_type="Lung Adenocarcinoma",
clinical={"age": 65, "sex": "Male", "stage": "II"},
)
# Vision-only inference: omit all text inputs.
vision_output = model.predict(patch_features=features, patch_coords=coords)
```
`predict` handles spatial views automatically and independently max-pools OS/PFS risks across views. Higher scores indicate higher predicted risk, not calibrated survival probabilities. Without WSI, `wsi_features` is `None`.
For genomics, omitted fields or `-1` mean unknown; `[]` means no qualifying alteration in the evaluated gene set. See the [GitHub repository](https://github.com/MAGIC-AI4Med/MOSAIC) for input conventions and task-specific evaluation protocols.