Embedding of whole slide images with Foundation Models
Project description
slide2vec
slide2vec is a Python package for efficient encoding of whole-slide images using publicly available foundation models. It builds on hs2p for fast preprocessing and exposes a focused surface around Model, Pipeline, and ExecutionOptions.
Installation
pip install slide2vec
Install the full model runtime only when you need embedding/model execution:
pip install "slide2vec[models]"
slide2vec now keeps the base install focused on the core package surface and moves the heavier model stack into the optional models extra.
Python API
from slide2vec import Model
from slide2vec.utils.config import hf_login
hf_login()
model = Model.from_preset("virchow2")
embedded = model.embed_slide("/path/to/slide.svs")
tile_embeddings = embedded.tile_embeddings
coordinates = embedded.coordinates
Use Pipeline(...) for manifest-driven batch processing when you want artifacts written to disk instead of only in-memory outputs:
from slide2vec import ExecutionOptions, Pipeline, PreprocessingConfig
pipeline = Pipeline(
model=model,
preprocessing=PreprocessingConfig(
target_spacing_um=0.5,
target_tile_size_px=224,
tissue_threshold=0.1,
),
execution=ExecutionOptions(output_dir="outputs/demo"),
)
result = pipeline.run(manifest_path="/path/to/slides.csv")
By default, ExecutionOptions() uses all available GPUs. Set ExecutionOptions(num_gpus=4) when you want to cap the sharding explicitly.
Input Manifest
Manifest-driven runs use the schema below. mask_path and spacing_at_level_0 are optional.
sample_id,image_path,mask_path,spacing_at_level_0
slide-1,/path/to/slide-1.svs,/path/to/mask-1.png,0.25
slide-2,/path/to/slide-2.svs,,
...
Use spacing_at_level_0 when the slide file reports a missing or incorrect level-0 spacing and you want to override it.
Outputs
The package writes explicit artifact directories:
tile_embeddings/<sample_id>.ptor.npztile_embeddings/<sample_id>.meta.jsonslide_embeddings/<sample_id>.ptor.npzslide_embeddings/<sample_id>.meta.json- optional
slide_latents/<sample_id>.ptor.npz
.pt remains the default format. .npz is available through ExecutionOptions(output_format="npz").
Supported Models
slide2vec currently ships preset configs for 20 tile-level models and 3 slide-level models.
For the full catalog and preset names, see docs/models.md.
CLI
The CLI is a thin wrapper over the package API.
Bundled configs live under slide2vec/configs/preprocessing/ and slide2vec/configs/models/.
python -m slide2vec --config-file /path/to/config.yaml
By default, manifest-driven CLI runs use all available GPUs. Set speed.num_gpus=4 when you want to cap the sharding explicitly.
New to the CLI or doing batch runs to disk? Start with docs/cli.md for the config-driven workflow, overrides, and common run patterns.
Docker
Docker remains available when you prefer a containerized runtime:
docker pull waticlems/slide2vec:latest
docker run --rm -it \
-v /path/to/your/data:/data \
-e HF_TOKEN=<your-huggingface-api-token> \
waticlems/slide2vec:latest
Documentation
docs/cli.mdfor the config-driven CLI guidedocs/python-api.mdfor the detailed API referencetutorials/api_walkthrough.ipynbfor a notebook walkthrough of the APIdocs/models.mdfor the full supported-model catalog
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slide2vec-3.2.0.tar.gz.
File metadata
- Download URL: slide2vec-3.2.0.tar.gz
- Upload date:
- Size: 111.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
284a63d5e605a4da542176bddc8b5759ce0a8e10b96bd17337b594fce9ce1001
|
|
| MD5 |
ce84172a766b4a94bb38aa24dded32c6
|
|
| BLAKE2b-256 |
9464f80c8ae6a545a7a8ca76b08cf2c872793b3a4a204c9eff41afa301c4ce98
|
File details
Details for the file slide2vec-3.2.0-py3-none-any.whl.
File metadata
- Download URL: slide2vec-3.2.0-py3-none-any.whl
- Upload date:
- Size: 95.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adcbacd5f037cdcaf8c5bd9496ad0f509a45705652aac5335b89fe965562fc32
|
|
| MD5 |
09ad6c70c42bcee5f8a0f2058258b85a
|
|
| BLAKE2b-256 |
9e8e6d9f7ac0083c769e34376bdd6f5bf004cf1b68a50d7dd9db6363301627ce
|