slide2vec
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.
Install
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.
Reproducible model environments
The repository ships a uv.lock file that pins every package for each extra. From a checkout, uv sync --extra cu128 --extra fm installs the exact locked stack (use --extra cpu for CPU-only PyTorch). Add --extra flash-attn for PRISM2 and gigapath-slide. The Docker image is built from the same lock; its SLIDE2VEC_EXTRAS build argument selects the extras, for example --build-arg SLIDE2VEC_EXTRAS="cu128" for the base install only.
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.
Embed a slide
from hs2p import TilingConfig
from slide2vec import Model, PreprocessingConfig
model = Model.from_preset("virchow2")
preprocessing = PreprocessingConfig(
tiling=TilingConfig(
requested_spacing_um=0.5, requested_tile_size_px=224, tolerance=0.05, overlap=0.0
),
)
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
tiling is an hs2p TilingConfig. Leave it unset to take spacing and tile size from the preset; Virchow2 supports several scales, so it needs an explicit one. The preset also supplies precision. 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.
Save a batch
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
pipeline = Pipeline(
model=Model.from_preset("virchow2"),
preprocessing=preprocessing, # from the example above
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
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.
More documentation
Metadata
Release files for slide2vec 7.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| slide2vec-7.1.3.tar.gz | 439.7 kB | Without provenance | Details for slide2vec-7.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slide2vec-7.1.3-py3-none-any.whl | Python 3 | none | any | Details for slide2vec-7.1.3-py3-none-any.whl |
Total release size: 723.4 kB
Release files / slide2vec-7.1.3.tar.gz
| Download URL | slide2vec-7.1.3.tar.gz |
|---|---|
| Size | 439.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1e1a47f488bb76f2ed7653ff82285f820f7d9168ab17bf6d58f711bd90174ec
|
|
BLAKE2b-256 checksum How to use checksums |
cd361efe22b2f15d6bc6533ec9b5e95f3da0d6d083e59de2b3ea774820622463
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Release files / slide2vec-7.1.3-py3-none-any.whl
| Download URL | slide2vec-7.1.3-py3-none-any.whl |
|---|---|
| Size | 283.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe8eabdbe81a7ef265c5e1f1ff72fbb6638c9e6bd65b7750cd5e4bf48c638933
|
|
BLAKE2b-256 checksum How to use checksums |
d3de06a97592c39d901c6d7d2825757e3cd0c1c41a7d6757dae4206aaa276ec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Security for slide2vec 7.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.