Fast, scalable whole-slide encoding
16
stars
283
commits
Python
primary language
Sep 7, 2026
updated
slide2vec encodes whole-slide images with publicly available pathology foundation models. It uses hs2p for tissue detection and tiling, and handles batching, multi-GPU execution, and embedding storage.
Python 3.10 or newer is required:
pip install slide2vec
Many models need additional dependencies available through pip install "slide2vec[fm]". See the model installation guide for model-specific extras, separate environments, and upstream packages.
For gated models such as Virchow2, request access on the model's Hugging Face page and authenticate with hf auth login or an HF_TOKEN environment variable.
from slide2vec import Model, PreprocessingConfig
model = Model.from_preset("virchow2")
preprocessing = PreprocessingConfig(requested_spacing_um=0.5)
embedded = model.embed_slide("/path/to/slide.svs", preprocessing=preprocessing)
tile_embeddings = embedded.tile_embeddings # (N, 2560)
x, y = embedded.x, embedded.y # level-0 tile coordinates
The preset supplies tile size and precision defaults. Declare spacing explicitly for models such as Virchow2 that support several scales. Use list_models() to list presets, or filter with list_models("tile"), list_models("slide"), or list_models("patient").
See getting started for preprocessing and execution settings, and the API guide for patient embeddings, image inputs, and dense grids.
Create a CSV manifest:
sample_id,image_path
slide-1,/data/slide-1.svs
slide-2,/data/slide-2.svs
Optional mask_path and spacing_at_level_0 columns supply a mask or correct missing or incorrect level-0 spacing. Patient-level models also require patient_id; see the manifest schema.
from slide2vec import ExecutionOptions, Model, Pipeline, PreprocessingConfig
pipeline = Pipeline(
model=Model.from_preset("virchow2"),
preprocessing=PreprocessingConfig(requested_spacing_um=0.5),
execution=ExecutionOptions(output_dir="outputs/run"),
)
result = pipeline.run(manifest_path="/path/to/slides.csv")
Runs use all available GPUs by default; set ExecutionOptions(num_gpus=2) to limit them. Embeddings are saved as .pt tensors with metadata sidecars. Use ExecutionOptions(output_format="npz") for NumPy archives. The output guide describes directories, shapes, coordinates, and progress records.
Add region_tile_multiple=6 to the preprocessing config to group tiles into 6×6 regions. These produce (num_regions, 36, feature_dim) tensors in hierarchical_embeddings/; see hierarchical features.
The same batch workflow is available from the terminal:
slide2vec /path/to/config.yaml
The CLI guide provides a complete config example, overrides, and resume instructions.
docker pull waticlems/slide2vec:latest
docker run --rm -it \
-v /path/to/your/data:/data \
-e HF_TOKEN \
waticlems/slide2vec:latest
Set HF_TOKEN in your shell before starting the container.
281 commits
2 commits
Python
99.7%
Fast, scalable whole-slide encoding
16
stars
283
commits
Python
primary language
Sep 7, 2026
updated
slide2vec encodes whole-slide images with publicly available pathology foundation models. It uses hs2p for tissue detection and tiling, and handles batching, multi-GPU execution, and embedding storage.
Python 3.10 or newer is required:
pip install slide2vec
Many models need additional dependencies available through pip install "slide2vec[fm]". See the model installation guide for model-specific extras, separate environments, and upstream packages.
For gated models such as Virchow2, request access on the model's Hugging Face page and authenticate with hf auth login or an HF_TOKEN environment variable.
from slide2vec import Model, PreprocessingConfig
model = Model.from_preset("virchow2")
preprocessing = PreprocessingConfig(requested_spacing_um=0.5)
embedded = model.embed_slide("/path/to/slide.svs", preprocessing=preprocessing)
tile_embeddings = embedded.tile_embeddings # (N, 2560)
x, y = embedded.x, embedded.y # level-0 tile coordinates
The preset supplies tile size and precision defaults. Declare spacing explicitly for models such as Virchow2 that support several scales. Use list_models() to list presets, or filter with list_models("tile"), list_models("slide"), or list_models("patient").
See getting started for preprocessing and execution settings, and the API guide for patient embeddings, image inputs, and dense grids.
Create a CSV manifest:
sample_id,image_path
slide-1,/data/slide-1.svs
slide-2,/data/slide-2.svs
Optional mask_path and spacing_at_level_0 columns supply a mask or correct missing or incorrect level-0 spacing. Patient-level models also require patient_id; see the manifest schema.
from slide2vec import ExecutionOptions, Model, Pipeline, PreprocessingConfig
pipeline = Pipeline(
model=Model.from_preset("virchow2"),
preprocessing=PreprocessingConfig(requested_spacing_um=0.5),
execution=ExecutionOptions(output_dir="outputs/run"),
)
result = pipeline.run(manifest_path="/path/to/slides.csv")
Runs use all available GPUs by default; set ExecutionOptions(num_gpus=2) to limit them. Embeddings are saved as .pt tensors with metadata sidecars. Use ExecutionOptions(output_format="npz") for NumPy archives. The output guide describes directories, shapes, coordinates, and progress records.
Add region_tile_multiple=6 to the preprocessing config to group tiles into 6×6 regions. These produce (num_regions, 36, feature_dim) tensors in hierarchical_embeddings/; see hierarchical features.
The same batch workflow is available from the terminal:
slide2vec /path/to/config.yaml
The CLI guide provides a complete config example, overrides, and resume instructions.
docker pull waticlems/slide2vec:latest
docker run --rm -it \
-v /path/to/your/data:/data \
-e HF_TOKEN \
waticlems/slide2vec:latest
Set HF_TOKEN in your shell before starting the container.
281 commits
2 commits
Python
99.7%