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 example.py from Astaxanthin/MOSAIC: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/Astaxanthin/MOSAIC/resolve/main/example.py
- Command line
-
hf download hf://Astaxanthin/MOSAIC/example.py
-
curl -L -o example.py https://huggingface.co/Astaxanthin/MOSAIC/resolve/main/example.py
1.19 kB
| import argparse | |
| import torch | |
| from transformers import AutoModel | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model", required=True, help="Local model folder or HF repository ID") | |
| parser.add_argument("--device", default="cpu") | |
| args = parser.parse_args() | |
| model = AutoModel.from_pretrained(args.model, trust_remote_code=True).to(args.device).eval() | |
| # Synthetic input for checking installation, not a clinical prediction example. | |
| generator = torch.Generator().manual_seed(42) | |
| features = torch.randn(4, 768, generator=generator) | |
| coords = torch.tensor([[0,0], [0,256], [256,0], [256,256]]) | |
| output = model.predict(patch_features=features, patch_coords=coords, | |
| cancer_type="Lung Adenocarcinoma", | |
| clinical={"age":65,"sex":"Male","stage":"II"}, | |
| genomics={"snv":["TP53"],"cnv":[]}) | |
| print("WSI features:", output["wsi_features"].shape) | |
| print("OS risk:", output["os_risk"].tolist()) | |
| print("PFS risk:", output["pfs_risk"].tolist()) | |
| print("Views:", output["num_views"]) | |
| if __name__ == "__main__": | |
| main() | |