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.

Installation

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.

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 for input conventions and task-specific evaluation protocols.

Downloads last month
58
Safetensors
Model size
0.2B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support