Feature Extraction
Transformers
Safetensors
English
mosaic
computational-pathology
multimodal
survival-analysis
custom_code
Instructions to use Astaxanthin/MOSAIC with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Astaxanthin/MOSAIC with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Astaxanthin/MOSAIC", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Astaxanthin/MOSAIC", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from Astaxanthin/MOSAIC: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/Astaxanthin/MOSAIC/resolve/main/README.md
- Command line
-
hf download hf://Astaxanthin/MOSAIC/README.md
-
curl -L -o README.md https://huggingface.co/Astaxanthin/MOSAIC/resolve/main/README.md
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. | |