Instructions to use xusinuo/PARSE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xusinuo/PARSE with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="xusinuo/PARSE", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("xusinuo/PARSE", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
🧬 PARSE
Connecting histopathology with molecular profiles
Spatial gene expression · Protein prediction · Cell-type deconvolution
🤗 Download PARSE on Hugging Face · GitHub · MIT License
PARSE learns molecular representations of histopathology images from spatial transcriptomics. It takes H&E image patches as input and returns 768-dimensional patch embeddings and marker gene expression predictions.
This repository provides the image encoder, expression prediction head, cached embeddings for 15,032 genes, and a separately fine-tuned protein head. Downstream applications include spatial gene expression prediction, protein prediction, cell-type deconvolution, and whole-slide expression prediction.
Installation
Download the repository and install its dependencies:
pip install "huggingface_hub==0.36.0"
hf download xusinuo/PARSE --local-dir PARSE
cd PARSE
pip install -r requirements.txt
Usage
Load the model with AutoModel and run inference on one included H&E image:
import torch
from PIL import Image
from transformers import AutoModel
from model import amp, load_gene_embeddings
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModel.from_pretrained(
".", trust_remote_code=True,
).to(device).eval()
preprocess = model.get_image_transform()
image = Image.open("example_data/images/AACCAACAATCGGTAC-1.png").convert("RGB")
pixels = preprocess(image).unsqueeze(0).to(device)
genes = load_gene_embeddings(
"gene_embeddings.pt", ["COL1A2", "IGHA1", "FABP4"],
).to(device)
with torch.inference_mode(), amp(device):
features = model.encode_image(pixels)
expression = model.predict_expression(features, genes)
print("Patch embeddings:", features.shape) # [1, 768]
print("Gene expression:", expression.shape) # [1, 3]
To load the model directly from the Hub, replace "." with "xusinuo/PARSE" in AutoModel.from_pretrained(). The example above uses the downloaded local files.
The model also supports model(pixel_values=pixels, gene_embeddings=genes), returning a dictionary with image_features and expression. Inputs must be on the same device as the model. Gene vectors follow the requested gene order.
Example data
Run example.py to predict COL1A2, IGHA1 and FABP4 for one included image and save a CSV:
python example.py --output predictions.csv
For your own data:
python example.py --image patch.png --genes ESR1 ERBB2 MKI67 --output predictions.csv
Pass a single image file (for example, PNG or JPEG) with --image. The example_data/images folder contains 16 lossless PNG patches, named by their original patch IDs. Whole-slide images can be tiled separately using Trident.
The included patches come from the curated Breast/P29 ST demonstration. Processed expression targets and data sources are documented in example_data/README.md.
Downstream notebooks and data
The PARSE GitHub repository provides ST, protein, deconvolution and TCGA notebooks. The demo_data folder retains the H5 inputs used by the notebooks: 128 ST patches, 128 protein patches and the complete 2,747-patch Kidney deconvolution example, together with processed targets, task configs and class prototypes.
Run python download_assets.py from the GitHub repository to download the weights and demo data into the notebook input folders. TCGA uses user-prepared RGB patches; no TCGA images are included.
Model files
| File | Description |
|---|---|
model.safetensors |
Image encoder, visual projection, adapter and expression head weights loaded by AutoModel. |
parse.pt |
Full PyTorch checkpoint. Not required for AutoModel inference. |
gene_embeddings.pt |
Gene names and their cached embeddings. |
protein_head.pt |
Fine-tuned protein prediction head and target scaling statistics. |
Input and output conventions
Images are resized and center-cropped to 224 × 224 and normalized with ImageNet statistics. Image features are returned without final L2 normalization. Expression predictions are on the processed target scale, not raw sequencing counts.
Protein prediction uses its own head, target scaling and tensor-based image preprocessing. Deconvolution optimizes cell-type proportions against class prototypes outside the model. The gene interface selects cached embeddings; arbitrary gene text encoding is not exposed by this release.
License
PARSE code and released model weights are licensed under the MIT License. Copyright © 2026 MAGIC: Medical Artificial General Intelligence Consortium.
KEEP-derived components retain their original MIT notice. Third-party example data and gene annotations remain subject to their respective source licenses and terms; they are not relicensed by PARSE.
- Downloads last month
- 52