Pull the pre-built Docker image directly from Docker Hub (includes all dependencies and code):
# Pull the latest PASTA image
docker pull bm2labtongji/pasta:latest
# Run demo
docker run --gpus all --shm-size=16g -it --rm \
-v .:/workspace/results \
bm2labtongji/pasta:latest \
python demo.py
For Podman users:
podman pull bm2labtongji/pasta:latest
podman run --device nvidia.com/gpu=all --shm-size=16g -it --rm \
-v .:/workspace/results \
bm2labtongji/pasta:latest \
python demo.py
Docker Compose
# Start
docker-compose up -d
# Stop
docker-compose down
# View logs
docker-compose logs -f
The docker-compose.yml file includes:
To customize settings, create a .env file in the project root:
HF_TOKEN=your_huggingface_token_here
CUDA_VISIBLE_DEVICES=0
HF_ENDPOINT=https://hf-mirror.com
Clone the repository and build the Docker image locally:
git clone https://github.com/DELTA-TJ-submission/PASTA.git
cd PASTA
# Build image
docker build -t pasta:latest .
# Run demo
docker run --gpus all --shm-size=16g -it --rm \
pasta:latest \
python demo.py
Install from source using conda and pip:
# Clone repository
git clone https://github.com/DELTA-TJ-submission/PASTA.git
cd PASTA
# Create conda environment
conda env create -f environment.yml
conda activate pasta
# Install PASTA
pip install -e .
Optional: To leverage GPU acceleration for data processing, we recommend installing RAPIDS in your conda environment.
The following specifications are based on our experimental setup and provided as reference.
Some foundation models require access permissions from their respective repositories. To use these models:
pasta/configs/demo.json and pasta/configs/inference.json):endpoint field:{
"huggingface": {
"token": "hf_your_token_here",
"endpoint": "https://hf-mirror.com"
}
}
Note: The token and endpoint will be automatically applied when loading models that require Hugging Face authentication.
Run the demo pipeline to process a sample WSI data/demo.ome.tif and generate predictions:
python demo.py
This will execute the complete workflow:
The demo uses the configuration in code/configs/demo.json. Results will be saved in the results/demo/ directory:
patches/: Extracted image patches (H5 format)masks/: Tissue segmentation masksstitches/: Visualization of patch coordinatespredictions/: Model predictions and visualizationsπ¨ PASTA now includes a user-friendly web interface for easy prediction
π§ This feature is still a work in progress
PASTA Web Interface
# Start the web interface
python web_ui.py
Then open your browser and navigate to http://localhost:7860
python web_ui.py [OPTIONS]
Options:
--host TEXT Host address (default: 0.0.0.0)
--port INTEGER Port number (default: 7860)
--share Create public share link for remote access
--debug Enable debug mode
# Run with web interface exposed
docker run --gpus all -p 7860:7860 -it bm2labtongji/pasta:latest python web_ui.py
# For Podman
podman run --device nvidia.com/gpu=all -p 7860:7860 -it bm2labtongji/pasta:latest python web_ui.py
π For detailed Web UI usage instructions, see WEB_UI_README.md
Extract patches from whole slide images:
python -m code.create_patches_fp \
--source data/wsis \
--save_dir results/patches \
--patch_size 256 \
--step_size 128 \
--seg --patch --stitch
Key Parameters:
--source: Directory containing WSI files--save_dir: Output directory for patches and metadata--patch_size: Size of extracted patches (default: 256)--step_size: Stride between patches (default: 256)--seg: Enable tissue segmentation--patch: Enable patch extraction--stitch: Create visualization of patch layout--auto_patch_size: Automatically adjust patch size based on WSI resolution (MPP)π
inference_without_process.pycan perform inference without the need for h5_file_processing. The script is still in testing.
Process H5 files to extract image data and metadata:
python -m code.process_patch_h5 \
--patch_size 256 \
--h5_path results/patches \
--slide_path data/wsis \
--file_type .svs \
--save_edge \
--edge_info_path results/edge_info
Key Parameters:
--patch_size: Patch size for extraction (default: 224)--h5_path: Directory containing H5 coordinate files--slide_path: Directory containing original WSI files--file_type: WSI file extension (.svs, .mrxs, .tiff, .tif)--save_edge: Save bounding box information as JSON--mask_path: Optional path to GeoJSON mask files for ROI processing--max_workers: Number of parallel workers (default: 8)ROI-based Analysis:
PASTA supports targeted region-level analysis by ingesting ROI annotations exported from QuPath (GeoJSON/JSON format). This enables focused inference on specific areas of interest to pathologists, reducing computational overhead while enabling precise spatial analysis.
Left: ROI annotation in QuPath; Right: Prediction result on selected region
Processing with ROI masks:
python -m code.process_patch_h5 \
--patch_size 256 \
--h5_path results/patches \
--slide_path data/wsis \
--file_type .svs \
--mask_path data/masks \
--save_edge
This will create separate H5 files for each ROI defined in the GeoJSON masks.
π
inference_parallel.pyenables parallel processing of multiple WSI slides across multiple GPUs, speeding up inference for large datasets.
PASTA supports two inference modes:
Generate high-resolution spatial predictions with visualization:
python -m code.inference
Configure inference in code/configs/inference.json:
{
"inference": {
"backbone_model_name": "UNI",
"model_path": "model/UNI_pos_embed.pt",
"h5_path": "results/patches/",
"wsi_path": "data/wsis/",
"output_path": "results/predictions",
"prediction_mode": "pixel",
"downsample_size": 10,
"draw_images": true,
"save_h5ad": true
}
}
Key Parameters:
prediction_mode: Set to "pixel" for high-resolution predictiondownsample_size: Downsampling factor for output (default: 10)draw_images: Generate visualization plotssave_h5ad: Save results in AnnData formatsave_tiffs: Export predictions as QuPath-compatible TIFF filesselected_pathways: List of specific pathways to predict (null = all)include_tls: Include Tertiary Lymphoid Structure (TLS) predictionFast prediction for large datasets:
{
"inference": {
"prediction_mode": "spot",
"output_path": "results/predictions_h5ad"
}
}
Spot-level mode generates patch-level predictions in h5ad format suitable for spatial transcriptomics analysis tools like Scanpy.
Define pathways in code/configs/pathways.json:
{
"default_14": {
"names": ["CAF", "Endothelial", "Epithelial", "B_cells", "T_cells", ...],
"tls_components": ["B_cells", "T_cells"]
}
}
PASTA generates high-resolution spatial predictions that can be visualized in QuPath or other pathology viewers:
Interactive visualization of PASTA predictions in QuPath showing detailed spatial patterns at multiple magnifications
The predictions can be exported as:
Train PASTA models using Distributed Data Parallel (DDP):
PASTA can be trained directly using the HEST-Library dataset, or you can organize your own training data as follows:
data_train/
βββ meta.csv # Sample metadata
βββ patches/ # H5 files with patches
β βββ sample001.h5
β βββ sample002.h5
β βββ ...
βββ st/
β βββ sample001.h5ad # ST h5ad files
β βββ sample002.h5ad
β βββ ...
βββ gene/
β βββ sample001.csv # Gene expression
β βββ sample002.csv
β βββ ...
βββ pathway/
β βββ sample001.csv # Pathway scores
β βββ sample002.csv
β βββ ...
βββ wsis/
β βββ sample001.tif # HE images
β βββ sample002.tif
β βββ ...
You can set info_dir to either the gene/ or pathway/ directory, depending on whether you want to use gene expression or pathway scores as input.
meta.csv format:
id
sample001
sample002
...
Edit code/configs/train.json:
{
"model": {
"backbone_model": "UNI",
"non_negative": false,
"enable_attention_hooks": false
},
"data": {
"meta_path": "data_train/meta.csv",
"tile_h5_base": "data_train/patches",
"info_base": "data_train/info_input",
"train_ratio": 0.8,
"random_seed": 42
},
"pathway": {
"info_type": "expression",
"output_dim": 14
},
"training": {
"epochs": 100,
"batch_size": 64,
"learning_rate": 0.0001,
"augment": true
},
"output": {
"output_dir": "results/train/UNI"
}
}
Single GPU:
CUDA_VISIBLE_DEVICES=0 torchrun --nproc_per_node=1 \
--master_addr="localhost" \
code/train.py
Multi-GPU:
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 \
--master_addr="localhost" \
code/train.py
Training outputs:
results/train/UNI/model_state_dict_*.pthresults/train/UNI/best_model.ptresults/train/UNI/runs/train_df.csv, test_df.csvCurrently PASTA supports 16 state-of-the-art pathological foundation models:
| Model name | Structure | Layers | Embed size | Params | Dataset | Training recipe |
|---|---|---|---|---|---|---|
| CONCH | ViT-B/16 | 12 | 768 | 86.6M | 1.17M image-caption pairs | CLIP |
| Phikon | ViT-B/16 | 12 | 768 | 85.8M | 6,093 slides | iBOT |
| Phikon v2 | ViT-L/16 | 24 | 1024 | 0.3B | PANCAN-XL, 60K slides | DINOv2 |
| Kaiko-B | ViT-B/8 | 12 | 768 | 85.8M | TCGA | DINO |
| Kaiko-L | ViT-L/14 | 24 | 1024 | 304.4M | TCGA | DINO |
| Hibou-B | ViT-B/14 | 12 | 768 | 85.7M | 1.2B images private dataset | DINOv2 |
| Hibou-L | ViT-L/14 | 24 | 1024 | 0.3B | 1.2B images private dataset | DINOv2 |
| UNI | ViT-L/16 | 24 | 1024 | 0.3B | 100,426 slides | DINOv2 |
| UNIv2 | ViT-G/14 | 24 | 1536 | 681M | Over 300k H&E and IHC slides | DINOv2 |
| Virchow | ViT-H/14 | 32 | 1280 | 632M | 1.5M slides | DINOv2 |
| Virchow2 | ViT-H/14 | 32 | 1280 | 632M | 3.1M slides | Modified DINOv2 |
| H-optimus-0 | ViT-G/14 | 40 | 1536 | 1.1B | 0.5M slides | iBOT, DINOv2 |
| H-optimus-1 | ViT-G/14 | 40 | 1536 | 1.1B | Over 1M slides | Self-supervised learning |
| Gigapath | ViT-G/16 | 40 | 1536 | 1.13B | 1.3B Providence image tiles | DINOv2 |
| PLIP | ViT-B/32 | 12 | 768 | 87.5M | 208,414 slides paired with descriptions | CLIP |
| genbio-pathfm | ViT-G/16 | 40 | 1536 | 1.1B | 177,000 WSIs | JEPA + DINO |
Note: Model download links are provided above. Please refer to the original repos for access to model weights.
This section will include:
Our code and model weights are released under the GPLv3. See LICENSE for additional details.
If you find this repository useful, please consider giving a star β and citation:
@software{PASTA,
author = {Fangliangzi Meng},
title = {Gigapixel multilevel virtual tumor tissue phenotyping by pathological foundation models},
url = {https://github.com/DELTA-TJ-submission/PASTA},
year = {2025},
}
For questions and issues, please:
This project builds upon several excellent works:
14 commits
1 commits
Jupyter Notebook
99.0%
Pull the pre-built Docker image directly from Docker Hub (includes all dependencies and code):
# Pull the latest PASTA image
docker pull bm2labtongji/pasta:latest
# Run demo
docker run --gpus all --shm-size=16g -it --rm \
-v .:/workspace/results \
bm2labtongji/pasta:latest \
python demo.py
For Podman users:
podman pull bm2labtongji/pasta:latest
podman run --device nvidia.com/gpu=all --shm-size=16g -it --rm \
-v .:/workspace/results \
bm2labtongji/pasta:latest \
python demo.py
Docker Compose
# Start
docker-compose up -d
# Stop
docker-compose down
# View logs
docker-compose logs -f
The docker-compose.yml file includes:
To customize settings, create a .env file in the project root:
HF_TOKEN=your_huggingface_token_here
CUDA_VISIBLE_DEVICES=0
HF_ENDPOINT=https://hf-mirror.com
Clone the repository and build the Docker image locally:
git clone https://github.com/DELTA-TJ-submission/PASTA.git
cd PASTA
# Build image
docker build -t pasta:latest .
# Run demo
docker run --gpus all --shm-size=16g -it --rm \
pasta:latest \
python demo.py
Install from source using conda and pip:
# Clone repository
git clone https://github.com/DELTA-TJ-submission/PASTA.git
cd PASTA
# Create conda environment
conda env create -f environment.yml
conda activate pasta
# Install PASTA
pip install -e .
Optional: To leverage GPU acceleration for data processing, we recommend installing RAPIDS in your conda environment.
The following specifications are based on our experimental setup and provided as reference.
Some foundation models require access permissions from their respective repositories. To use these models:
pasta/configs/demo.json and pasta/configs/inference.json):endpoint field:{
"huggingface": {
"token": "hf_your_token_here",
"endpoint": "https://hf-mirror.com"
}
}
Note: The token and endpoint will be automatically applied when loading models that require Hugging Face authentication.
Run the demo pipeline to process a sample WSI data/demo.ome.tif and generate predictions:
python demo.py
This will execute the complete workflow:
The demo uses the configuration in code/configs/demo.json. Results will be saved in the results/demo/ directory:
patches/: Extracted image patches (H5 format)masks/: Tissue segmentation masksstitches/: Visualization of patch coordinatespredictions/: Model predictions and visualizationsπ¨ PASTA now includes a user-friendly web interface for easy prediction
π§ This feature is still a work in progress
PASTA Web Interface
# Start the web interface
python web_ui.py
Then open your browser and navigate to http://localhost:7860
python web_ui.py [OPTIONS]
Options:
--host TEXT Host address (default: 0.0.0.0)
--port INTEGER Port number (default: 7860)
--share Create public share link for remote access
--debug Enable debug mode
# Run with web interface exposed
docker run --gpus all -p 7860:7860 -it bm2labtongji/pasta:latest python web_ui.py
# For Podman
podman run --device nvidia.com/gpu=all -p 7860:7860 -it bm2labtongji/pasta:latest python web_ui.py
π For detailed Web UI usage instructions, see WEB_UI_README.md
Extract patches from whole slide images:
python -m code.create_patches_fp \
--source data/wsis \
--save_dir results/patches \
--patch_size 256 \
--step_size 128 \
--seg --patch --stitch
Key Parameters:
--source: Directory containing WSI files--save_dir: Output directory for patches and metadata--patch_size: Size of extracted patches (default: 256)--step_size: Stride between patches (default: 256)--seg: Enable tissue segmentation--patch: Enable patch extraction--stitch: Create visualization of patch layout--auto_patch_size: Automatically adjust patch size based on WSI resolution (MPP)π
inference_without_process.pycan perform inference without the need for h5_file_processing. The script is still in testing.
Process H5 files to extract image data and metadata:
python -m code.process_patch_h5 \
--patch_size 256 \
--h5_path results/patches \
--slide_path data/wsis \
--file_type .svs \
--save_edge \
--edge_info_path results/edge_info
Key Parameters:
--patch_size: Patch size for extraction (default: 224)--h5_path: Directory containing H5 coordinate files--slide_path: Directory containing original WSI files--file_type: WSI file extension (.svs, .mrxs, .tiff, .tif)--save_edge: Save bounding box information as JSON--mask_path: Optional path to GeoJSON mask files for ROI processing--max_workers: Number of parallel workers (default: 8)ROI-based Analysis:
PASTA supports targeted region-level analysis by ingesting ROI annotations exported from QuPath (GeoJSON/JSON format). This enables focused inference on specific areas of interest to pathologists, reducing computational overhead while enabling precise spatial analysis.
Left: ROI annotation in QuPath; Right: Prediction result on selected region
Processing with ROI masks:
python -m code.process_patch_h5 \
--patch_size 256 \
--h5_path results/patches \
--slide_path data/wsis \
--file_type .svs \
--mask_path data/masks \
--save_edge
This will create separate H5 files for each ROI defined in the GeoJSON masks.
π
inference_parallel.pyenables parallel processing of multiple WSI slides across multiple GPUs, speeding up inference for large datasets.
PASTA supports two inference modes:
Generate high-resolution spatial predictions with visualization:
python -m code.inference
Configure inference in code/configs/inference.json:
{
"inference": {
"backbone_model_name": "UNI",
"model_path": "model/UNI_pos_embed.pt",
"h5_path": "results/patches/",
"wsi_path": "data/wsis/",
"output_path": "results/predictions",
"prediction_mode": "pixel",
"downsample_size": 10,
"draw_images": true,
"save_h5ad": true
}
}
Key Parameters:
prediction_mode: Set to "pixel" for high-resolution predictiondownsample_size: Downsampling factor for output (default: 10)draw_images: Generate visualization plotssave_h5ad: Save results in AnnData formatsave_tiffs: Export predictions as QuPath-compatible TIFF filesselected_pathways: List of specific pathways to predict (null = all)include_tls: Include Tertiary Lymphoid Structure (TLS) predictionFast prediction for large datasets:
{
"inference": {
"prediction_mode": "spot",
"output_path": "results/predictions_h5ad"
}
}
Spot-level mode generates patch-level predictions in h5ad format suitable for spatial transcriptomics analysis tools like Scanpy.
Define pathways in code/configs/pathways.json:
{
"default_14": {
"names": ["CAF", "Endothelial", "Epithelial", "B_cells", "T_cells", ...],
"tls_components": ["B_cells", "T_cells"]
}
}
PASTA generates high-resolution spatial predictions that can be visualized in QuPath or other pathology viewers:
Interactive visualization of PASTA predictions in QuPath showing detailed spatial patterns at multiple magnifications
The predictions can be exported as:
Train PASTA models using Distributed Data Parallel (DDP):
PASTA can be trained directly using the HEST-Library dataset, or you can organize your own training data as follows:
data_train/
βββ meta.csv # Sample metadata
βββ patches/ # H5 files with patches
β βββ sample001.h5
β βββ sample002.h5
β βββ ...
βββ st/
β βββ sample001.h5ad # ST h5ad files
β βββ sample002.h5ad
β βββ ...
βββ gene/
β βββ sample001.csv # Gene expression
β βββ sample002.csv
β βββ ...
βββ pathway/
β βββ sample001.csv # Pathway scores
β βββ sample002.csv
β βββ ...
βββ wsis/
β βββ sample001.tif # HE images
β βββ sample002.tif
β βββ ...
You can set info_dir to either the gene/ or pathway/ directory, depending on whether you want to use gene expression or pathway scores as input.
meta.csv format:
id
sample001
sample002
...
Edit code/configs/train.json:
{
"model": {
"backbone_model": "UNI",
"non_negative": false,
"enable_attention_hooks": false
},
"data": {
"meta_path": "data_train/meta.csv",
"tile_h5_base": "data_train/patches",
"info_base": "data_train/info_input",
"train_ratio": 0.8,
"random_seed": 42
},
"pathway": {
"info_type": "expression",
"output_dim": 14
},
"training": {
"epochs": 100,
"batch_size": 64,
"learning_rate": 0.0001,
"augment": true
},
"output": {
"output_dir": "results/train/UNI"
}
}
Single GPU:
CUDA_VISIBLE_DEVICES=0 torchrun --nproc_per_node=1 \
--master_addr="localhost" \
code/train.py
Multi-GPU:
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 \
--master_addr="localhost" \
code/train.py
Training outputs:
results/train/UNI/model_state_dict_*.pthresults/train/UNI/best_model.ptresults/train/UNI/runs/train_df.csv, test_df.csvCurrently PASTA supports 16 state-of-the-art pathological foundation models:
| Model name | Structure | Layers | Embed size | Params | Dataset | Training recipe |
|---|---|---|---|---|---|---|
| CONCH | ViT-B/16 | 12 | 768 | 86.6M | 1.17M image-caption pairs | CLIP |
| Phikon | ViT-B/16 | 12 | 768 | 85.8M | 6,093 slides | iBOT |
| Phikon v2 | ViT-L/16 | 24 | 1024 | 0.3B | PANCAN-XL, 60K slides | DINOv2 |
| Kaiko-B | ViT-B/8 | 12 | 768 | 85.8M | TCGA | DINO |
| Kaiko-L | ViT-L/14 | 24 | 1024 | 304.4M | TCGA | DINO |
| Hibou-B | ViT-B/14 | 12 | 768 | 85.7M | 1.2B images private dataset | DINOv2 |
| Hibou-L | ViT-L/14 | 24 | 1024 | 0.3B | 1.2B images private dataset | DINOv2 |
| UNI | ViT-L/16 | 24 | 1024 | 0.3B | 100,426 slides | DINOv2 |
| UNIv2 | ViT-G/14 | 24 | 1536 | 681M | Over 300k H&E and IHC slides | DINOv2 |
| Virchow | ViT-H/14 | 32 | 1280 | 632M | 1.5M slides | DINOv2 |
| Virchow2 | ViT-H/14 | 32 | 1280 | 632M | 3.1M slides | Modified DINOv2 |
| H-optimus-0 | ViT-G/14 | 40 | 1536 | 1.1B | 0.5M slides | iBOT, DINOv2 |
| H-optimus-1 | ViT-G/14 | 40 | 1536 | 1.1B | Over 1M slides | Self-supervised learning |
| Gigapath | ViT-G/16 | 40 | 1536 | 1.13B | 1.3B Providence image tiles | DINOv2 |
| PLIP | ViT-B/32 | 12 | 768 | 87.5M | 208,414 slides paired with descriptions | CLIP |
| genbio-pathfm | ViT-G/16 | 40 | 1536 | 1.1B | 177,000 WSIs | JEPA + DINO |
Note: Model download links are provided above. Please refer to the original repos for access to model weights.
This section will include:
Our code and model weights are released under the GPLv3. See LICENSE for additional details.
If you find this repository useful, please consider giving a star β and citation:
@software{PASTA,
author = {Fangliangzi Meng},
title = {Gigapixel multilevel virtual tumor tissue phenotyping by pathological foundation models},
url = {https://github.com/DELTA-TJ-submission/PASTA},
year = {2025},
}
For questions and issues, please:
This project builds upon several excellent works:
14 commits
1 commits
Jupyter Notebook
99.0%