Repository navigation
LazySlide 0.13.0 runs tissue segmentation at each model's own resolution on whole slides, makes the acceleration switches work the same way across the API, and takes any model from the model zoo by registry key or as an instance. It requires lazyslide-models 0.1.0, which adds 21 models.
✨ Highlights
🧫 Tissue segmentation that fits in memory
zs.seg.tissue now runs GrandQC, PathProfiler and HEST over overlapping tiles and blends the results (#296, #297). Each model runs at its own resolution on whole slides, instead of at a coarser mpp to fit in memory. The new tile_px (default 1024) trades memory for context.
⚡ Acceleration switches across the API
amp, autocast_dtype, compile and compile_kws now work the same way everywhere, with defaults from zs.settings (#285). They are in feature_extraction, feature_aggregation, feature_prediction, tile_prediction, text_embedding, zero_shot_score, slide_caption, virtual_stain and image_generation, and in seg.cells, seg.tissue, seg.artifact and seg.semantic. prefetch_factor is available wherever num_workers is.
zs.settings.amp = True # for every call
zs.tl.feature_extraction(wsi, "uni2", compile=True) # or for one call🎨 Virtual staining for any model
zs.tl.virtual_stain handles a model by what it returns, not by its name (#291). It takes per-tile predictions such as ROSIE, per-pixel marker maps such as GigaTIME and gigatime-flash, and RGB virtual stains, including the weight-free color_deconvolution_map. ROSIE now keeps its raw values, and postprocess=True applies its display stretch (#293).
🗺️ Spatial context for feature prediction
Feature-prediction models can now ask for tile coordinates, or for the whole slide in one call (#286). STPath uses both:
from lazyslide_models.feature_prediction import STPath
zs.tl.feature_extraction(wsi, "gigapath")
zs.tl.feature_prediction(wsi, STPath(organ_type="Kidney", tech_type="Visium"))🧩 Any zoo model, by key or instance
model parameters take any registry key or model instance instead of a fixed list (#300). This covers seg.tissue, seg.artifact, seg.semantic, seg.zero_shot, tl.zero_shot_score and tl.slide_caption, which now uses the model you pass. Browse the models in the live catalogue, now embedded in the docs (#292).
🔍 Tissue detection inside the scanned area
On formats such as MRXS, zs.pp.find_tissues reads only the region inside the slide bounds (in_bounds=True, the default), so level="auto" can pick a finer level (#294). Refinement also reads only the region it needs.
📚 Docs
- New how-to: predict spatial gene expression from H&E with DeepSpot-M, by @KalinNonchev (#272).
- API pages for
zs.datasets,zs.seg.zero_shotandzs.io.read_ndpa(#302).
⚠️ Upgrade notes
Results that change
- Re-extract features. lazyslide-models 0.1.0 follows each encoder's upstream preprocessing, so many encoders give different features than before. Don't mix old and new features.
- Tissue masks change slightly: tiled inference (#296), PathProfiler at 2.5× (about 4 µm/px) as upstream, and the JPEG round trip for GrandQC only (#293).
seg.semanticandseg.artifactmasks change. Overlapping tiles are now blended as a weighted mean (#295); before, only the centre of each tile could pass the threshold.seg.zero_shotthresholds SAM probabilities at 0.5 (#293). Before, every pixel was foreground.pp.find_tissuesonly segments inside the slide bounds. Passin_bounds=Falsefor the old behaviour (#294).tl.feature_aggregationruns onsettings.device, not always on CPU (#285).tl.tile_prediction,tl.virtual_stainandseg.zero_shotfollowsettings.pbar, andseg.zero_shotalso followssettings.device(#299).- The datashader backend, used automatically above 10,000 shapes, honours
alpha(default 0.9; it was opaque), and an explicitbackend="matplotlib"now wins (#301).
Breaking changes
- The
lazyslide/zscommand-line tool is removed. It had been broken (#298). seg.artifactno longer accepts extra positional arguments (#299).lazyslide[all]now installs onlyscanpyandigraph, the optional packages LazySlide itself uses. Model dependencies such astransformersare inlazyslide[models](#302).
Deprecations
Deprecation warnings now reach you as FutureWarnings that point at your own code (#281, #299). Everything below is removed in v0.14.0:
| Deprecated | Use instead |
|---|---|
tl.feature_aggregation(by=) |
agg_by= |
tl.spatial_domain(layer=) |
layer_key= |
tl.tissue_props(key=) |
tissue_key= |
seg.zero_shot(show_progress=) |
pbar= |
RNALinker(gene_name=) |
gene_name= of plot_rank or associated_genes |
seg.cell_types |
seg.cells |
cv.transform.TissueDetectionHE |
pp.find_tissues |
lazyslide.models |
import lazyslide_models |
seg.semantic(low_memory=), seg.artifact(low_memory=), settings.pbar_impl, pbar= of the zs.datasets loaders, pp.tile_tissues(background_filter_mode=), BinaryMask.to_polygons(ignore_index=), ProbabilityMap(prob_map=) |
Nothing: they have no effect, so remove them |
Parameters added since v0.12.0 are keyword-only, so v0.12-style positional calls still bind the same way. See the deprecation policy.
📦 Dependencies
- Requires
lazyslide-models>=0.1.0(#304) andwsidata>=0.12.0(#294, #297). torchvision,scipy,numbaandhuggingface-hubare now declared dependencies.timmis no longer a direct one; it comes with lazyslide-models (#302).
🐛 Notable fixes
- Tile heatmaps line up with their tiles. The grid could be shifted by a tile (#279).
- Each
cv.transformtransform keeps its own parameters. Before, all instances shared one dict (#284). io.load_annotations(join_to=...)no longer shifts geometry and labels between shapes, andpl.tiles(title="...")no longer splits a string title into characters (#301).- Invalid tissue polygons are repaired, so cell segmentation no longer fails with a GEOS
TopologyException(#287).
🙌 New contributors
- @mxposed made their first contribution in #271, removing a redundant
tile_tissueswarning. - @KalinNonchev made their first contribution in #272, the DeepSpot-M how-to.
Thanks also to @AndreaMariani-AM for #273.
What's Changed
- fix: remove redundant warning if tissue_key is None in tile_tissues by @mxposed in #271
- fix(segmentation): convert OpenCV-decoded image from BGR to RGB before model transform by @AndreaMariani-AM in #273
- docs: predict spatial gene expression from H&E with DeepSpot-M by @KalinNonchev in #272
- chore: migrate to ruff 0.16.5 and pin it across pre-commit, CI and pyproject by @Mr-Milk in #280
- fix: find_stack_level pointed at pandas instead of lazyslide by @Mr-Milk in #281
- fix: Incorrect tiling heatmap rendering by @Mr-Milk in #279
- chore: fix RUF059 lint errors in heatmap grid test by @Mr-Milk in #282
- fix(cv): give each Transform its own params dict by @Mr-Milk in #284
- fix(cv): propagate transform errors in Mask2Polygon pipeline by @Mr-Milk in #283
- fix(seg): repair invalid tissue geometry, stop test polluting shared fixture by @Mr-Milk in #287
- feat(tools): let feature prediction models see coordinates and the whole slide by @Mr-Milk in #286
- feat: consistent inference acceleration params across the API by @Mr-Milk in #285
- refactor(tools): dispatch virtual_stain on the model's protocol by @Mr-Milk in #291
- docs: embed the live model zoo catalogue by @Mr-Milk in #292
- fix: preprocessing fixes from the lazyslide-models audit by @Mr-Milk in #293
- fix(pp): find_tissues memory use: refine budget, slide bounds, refine reads by @Mr-Milk in #294
- feat(seg): run tissue segmentation in overlapping tiles by @Mr-Milk in #296
- fix(seg): correct gaussian tile blending in semantic and artifact by @Mr-Milk in #295
- fix(seg): run the tissue model transform per tile by @Mr-Milk in #297
- refactor!: remove the broken CLI and dead internal code by @Mr-Milk in #298
- refactor: deprecation hygiene and API consistency by @Mr-Milk in #299
- refactor: model params take a registry key or a model instance by @Mr-Milk in #300
- fix: bugs found in the legacy-code audit by @Mr-Milk in #301
- chore: packaging and docs drift by @Mr-Milk in #302
- build: require lazyslide-models>=0.1.0 by @Mr-Milk in #304
Full Changelog: v0.12.0...v0.13.0