slide2vec 6.1.1__tar.gz → 6.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {slide2vec-6.1.1 → slide2vec-6.3.0}/PKG-INFO +3 -3
- {slide2vec-6.1.1 → slide2vec-6.3.0}/pyproject.toml +4 -4
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/__init__.py +1 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/api.py +20 -8
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/artifacts.py +7 -5
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/cli.py +1 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/configs/default.yaml +1 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/dense_worker.py +2 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/direct_embed_worker.py +6 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/image_worker.py +2 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/base.py +27 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/__init__.py +2 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/dinov2.py +32 -10
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/gigapath.py +22 -8
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/isight.py +2 -6
- slide2vec-6.3.0/slide2vec/encoders/models/lunit.py +55 -0
- slide2vec-6.3.0/slide2vec/encoders/models/mettle.py +183 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/mstar.py +28 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/phikon.py +2 -7
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/prism.py +15 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/titan.py +149 -16
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/registry.py +14 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/inference.py +54 -17
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/artifacts_collect.py +15 -5
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_image_recipe.py +15 -4
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_image_shard.py +18 -10
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_image_stage.py +15 -5
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_shard.py +45 -18
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_stage.py +34 -9
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/distributed_stage.py +5 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/embedding.py +16 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/embedding_persist.py +16 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/embedding_pipeline.py +15 -3
- slide2vec-6.3.0/slide2vec/runtime/feature_identity.py +271 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/image_shard.py +11 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/image_stage.py +51 -11
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/model_settings.py +5 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/patient_pipeline.py +29 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/persist_callbacks.py +37 -61
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/persistence.py +2 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/process_list.py +17 -10
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/serialization.py +2 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/slide_encode.py +35 -8
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/tiling_pipeline.py +5 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/config.py +0 -17
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/tiling_io.py +3 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/PKG-INFO +3 -3
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/SOURCES.txt +8 -1
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/requires.txt +2 -2
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_attention_extraction.py +0 -98
- slide2vec-6.3.0/tests/test_cli_noninteractive.py +77 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_cufile_compat_mode.py +0 -12
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_encode_kit.py +0 -36
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_encoder_input.py +0 -88
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_extraction.py +0 -71
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_image_reading.py +0 -29
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_image_resume.py +72 -6
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_image_shard.py +82 -26
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_image_stage.py +32 -71
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_shard.py +170 -37
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_sliding.py +0 -14
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_stage.py +118 -4
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_worker.py +1 -1
- slide2vec-6.3.0/tests/test_dinov2_natimage.py +39 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dinov3_natimage.py +3 -33
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_encoder_capabilities.py +1 -50
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_encoder_input_contract.py +0 -44
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_encoder_plugins.py +3 -8
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_encoder_preprocessing.py +51 -32
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_encoder_provider_failures.py +0 -42
- slide2vec-6.3.0/tests/test_encoder_registry.py +219 -0
- slide2vec-6.3.0/tests/test_feature_identity.py +904 -0
- slide2vec-6.3.0/tests/test_gigapath.py +100 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_hs2p5_integration.py +83 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_hs2p_package_cutover.py +0 -201
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_image_shard.py +21 -35
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_image_stage.py +114 -42
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_inference_benchmark.py +0 -15
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_isight.py +0 -65
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_load_model_hf_auth.py +0 -9
- slide2vec-6.3.0/tests/test_mascaret.py +99 -0
- slide2vec-6.3.0/tests/test_mettle.py +211 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_on_slide_persisted.py +1 -68
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_output_consistency.py +21 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_patch_size_metadata.py +9 -59
- slide2vec-6.3.0/tests/test_patient_annotation_sampling.py +187 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_phaet.py +0 -125
- slide2vec-6.3.0/tests/test_pooled_encoder_input.py +266 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_pooled_geometry.py +3 -51
- slide2vec-6.3.0/tests/test_prism.py +93 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_prism2.py +4 -196
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_process_list_performance.py +19 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_progress.py +5 -225
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_regression_core.py +31 -484
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_regression_inference.py +41 -950
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_regression_models.py +1 -193
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_rudolfv2.py +2 -334
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_sharding.py +0 -20
- slide2vec-6.3.0/tests/test_slide_latents.py +332 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_tile_store.py +0 -11
- slide2vec-6.3.0/tests/test_titan.py +363 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_worker_gpu_pinning.py +0 -7
- slide2vec-6.1.1/slide2vec/encoders/models/lunit.py +0 -24
- slide2vec-6.1.1/tests/test_architecture_runtime_split.py +0 -19
- slide2vec-6.1.1/tests/test_dinov2_natimage.py +0 -116
- slide2vec-6.1.1/tests/test_encoder_registry.py +0 -471
- slide2vec-6.1.1/tests/test_mascaret.py +0 -401
- slide2vec-6.1.1/tests/test_pooled_encoder_input.py +0 -634
- slide2vec-6.1.1/tests/test_prism.py +0 -52
- slide2vec-6.1.1/tests/test_titan.py +0 -134
- {slide2vec-6.1.1 → slide2vec-6.3.0}/LICENSE +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/README.md +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/setup.cfg +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/__main__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/_cufile.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/configs/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/configs/resources.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/cufile.json +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/data/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/data/dataset.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/data/tile_reader.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/data/tile_store.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/dense_image_worker.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/pin_gpu.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/pipeline_worker.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/distributed/worker_entry.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/conch.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/dinov3.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/genbio.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/gpfm.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/hibou.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/hoptimus.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/midnight.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/blocks.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/case.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/loading.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/slide.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/moozy/types.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/musk.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/prism2.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/prost40m.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/rudolfv2.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/uni.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/virchow.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/models/waiv.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/encoders/validation.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/progress.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/batching.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/cpu_budget.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_encode.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_encoder_input.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_image_reading.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_regions.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/dense_sliding.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/distributed.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/effective_encoder_input.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/encoder_input_contract.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/hierarchical.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/image_specs.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/manifest.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/pooled_encoder_input.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/preprocessing.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/progress_bridge.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/registry.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/sharding.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/tiling.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/types.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/runtime/worker_io.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/__init__.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/coordinates.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/log_utils.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec/utils/utils.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/dependency_links.txt +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/entry_points.txt +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/not-zip-safe +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/slide2vec.egg-info/top_level.txt +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_benchmark_tooling.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_regions.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_dense_source_spacing.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_gpfm_genbio_heavy.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_patient_manifest.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_runtime_batching.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_slide_coordinate_preparation.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_soma_migration.py +0 -0
- {slide2vec-6.1.1 → slide2vec-6.3.0}/tests/test_tiling_pipeline.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: slide2vec
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.3.0
|
|
4
4
|
Summary: Embedding of whole slide images with Foundation Models
|
|
5
5
|
Author-email: Clément Grisi <clement.grisi@radboudumc.nl>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: hs2p[asap,cucim,openslide,sam2,vips]>=5.0
|
|
18
|
+
Requires-Dist: hs2p[asap,cucim,openslide,sam2,tifffile,vips]>=5.1.0
|
|
19
19
|
Requires-Dist: omegaconf
|
|
20
20
|
Requires-Dist: matplotlib
|
|
21
21
|
Requires-Dist: numpy<2
|
|
@@ -75,7 +75,7 @@ Requires-Dist: numpy<2; extra == "fm"
|
|
|
75
75
|
Requires-Dist: pandas; extra == "fm"
|
|
76
76
|
Requires-Dist: pillow; extra == "fm"
|
|
77
77
|
Requires-Dist: rich; extra == "fm"
|
|
78
|
-
Requires-Dist: hs2p[asap,cucim,openslide,sam2,vips]>=5.0
|
|
78
|
+
Requires-Dist: hs2p[asap,cucim,openslide,sam2,tifffile,vips]>=5.1.0; extra == "fm"
|
|
79
79
|
Requires-Dist: wandb; extra == "fm"
|
|
80
80
|
Requires-Dist: torch<2.8,>=2.3; extra == "fm"
|
|
81
81
|
Requires-Dist: torchvision>=0.18.0; extra == "fm"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "slide2vec"
|
|
7
|
-
version = "6.
|
|
7
|
+
version = "6.3.0"
|
|
8
8
|
description = "Embedding of whole slide images with Foundation Models"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -21,7 +21,7 @@ classifiers = [
|
|
|
21
21
|
"Programming Language :: Python :: 3.13",
|
|
22
22
|
]
|
|
23
23
|
dependencies = [
|
|
24
|
-
"hs2p[asap,cucim,openslide,sam2,vips]>=5.0
|
|
24
|
+
"hs2p[asap,cucim,openslide,sam2,tifffile,vips]>=5.1.0",
|
|
25
25
|
"omegaconf",
|
|
26
26
|
"matplotlib",
|
|
27
27
|
"numpy<2",
|
|
@@ -100,7 +100,7 @@ fm = [
|
|
|
100
100
|
"pandas",
|
|
101
101
|
"pillow",
|
|
102
102
|
"rich",
|
|
103
|
-
"hs2p[asap,cucim,openslide,sam2,vips]>=5.0
|
|
103
|
+
"hs2p[asap,cucim,openslide,sam2,tifffile,vips]>=5.1.0",
|
|
104
104
|
"wandb",
|
|
105
105
|
"torch>=2.3,<2.8",
|
|
106
106
|
"torchvision>=0.18.0",
|
|
@@ -180,7 +180,7 @@ no_implicit_reexport = true
|
|
|
180
180
|
max-line-length = 160
|
|
181
181
|
|
|
182
182
|
[tool.bumpver]
|
|
183
|
-
current_version = "6.
|
|
183
|
+
current_version = "6.3.0"
|
|
184
184
|
version_pattern = "MAJOR.MINOR.PATCH"
|
|
185
185
|
commit = false
|
|
186
186
|
tag = false
|
|
@@ -153,8 +153,10 @@ class PreprocessingConfig:
|
|
|
153
153
|
#: explicitly (e.g. ``"openslide"``) when a precomputed tissue or annotation mask needs
|
|
154
154
|
#: a different decoder than its slide — hs2p no longer silently falls back to another
|
|
155
155
|
#: reader, so a mask the slide backend cannot decode fails unless overridden here.
|
|
156
|
-
#: Accepts the same values as :attr:`backend` plus ``"pil"`` for PNG/JPEG masks
|
|
157
|
-
#: ``"
|
|
156
|
+
#: Accepts the same values as :attr:`backend` plus ``"pil"`` for PNG/JPEG masks and
|
|
157
|
+
#: ``"tifffile"`` for lossless label reads; ``"auto"`` selects PIL for PNG/JPEG masks
|
|
158
|
+
#: and ``"tifffile"`` for TIFF masks whose samples are not 8-bit unsigned.
|
|
159
|
+
#: Ignored for slides with no source mask.
|
|
158
160
|
#: Masks need no spacing metadata, but must align to the slide's field of view and
|
|
159
161
|
#: contain only declared label IDs. See :doc:`preprocessing` for hs2p 5 validation.
|
|
160
162
|
mask_backend: str = "auto"
|
|
@@ -179,6 +181,10 @@ class PreprocessingConfig:
|
|
|
179
181
|
read_tiles_from: Path | None = None
|
|
180
182
|
#: Read and decode tiles on demand rather than pre-loading into memory.
|
|
181
183
|
on_the_fly: bool = True
|
|
184
|
+
#: Write the extracted tiles to ``tiles/<sample_id>.tiles.tar`` next to the coordinate
|
|
185
|
+
#: artifacts. Tiles are also written when ``on_the_fly`` is ``False`` and
|
|
186
|
+
#: ``read_tiles_from`` is unset, because embedding then reads them from the archive.
|
|
187
|
+
save_tiles: bool = False
|
|
182
188
|
#: Decode tiles on the GPU via CuCIM / nvImageCodec when ``True``.
|
|
183
189
|
gpu_decode: bool = False
|
|
184
190
|
#: Dynamically adjust batch size based on tile count.
|
|
@@ -285,6 +291,7 @@ class PreprocessingConfig:
|
|
|
285
291
|
Path(read_tiles_from) if read_tiles_from else None
|
|
286
292
|
),
|
|
287
293
|
on_the_fly=on_the_fly,
|
|
294
|
+
save_tiles=bool(cfg.save_tiles),
|
|
288
295
|
gpu_decode=gpu_decode,
|
|
289
296
|
adaptive_batching=adaptive_batching,
|
|
290
297
|
use_supertiles=bool(tiling.use_supertiles),
|
|
@@ -336,7 +343,8 @@ class ExecutionOptions:
|
|
|
336
343
|
save_tile_embeddings: bool = False
|
|
337
344
|
#: Persist slide embeddings to disk when running a patient-level model.
|
|
338
345
|
save_slide_embeddings: bool = False
|
|
339
|
-
#:
|
|
346
|
+
#: Return and persist the slide encoder's latent representations (PRISM). Encoders
|
|
347
|
+
#: without latents ignore it.
|
|
340
348
|
save_latents: bool = False
|
|
341
349
|
|
|
342
350
|
@classmethod
|
|
@@ -622,10 +630,13 @@ class EmbeddedSlide:
|
|
|
622
630
|
mask_preview_path: Path | None = None
|
|
623
631
|
#: Path to the tiling preview image, if generated.
|
|
624
632
|
tiling_preview_path: Path | None = None
|
|
625
|
-
#:
|
|
633
|
+
#: Slide encoder latent representations when ``ExecutionOptions.save_latents`` is set
|
|
634
|
+
#: and the encoder has them (PRISM: shape ``(512, 1280)``); ``None`` otherwise.
|
|
626
635
|
latents: Any | None = None
|
|
627
636
|
#: Factual square tensor side length immediately before tile encoding.
|
|
628
637
|
encoder_input_size_px: int | None = None
|
|
638
|
+
#: Record of the image transform applied before tile encoding (JSON data).
|
|
639
|
+
transform: dict[str, Any] | None = None
|
|
629
640
|
|
|
630
641
|
|
|
631
642
|
class Model:
|
|
@@ -892,8 +903,8 @@ class Model:
|
|
|
892
903
|
dense transform, and written to ``dense_embeddings/[<class>/]<sample_id>/<x>_<y>.pt``
|
|
893
904
|
plus a geometry sidecar. The run splits its ROIs across all visible GPUs
|
|
894
905
|
(``execution.num_gpus``); ``num_gpus=1`` encodes fully in-process. Resume is
|
|
895
|
-
automatic — only ROIs whose sidecar has the same source-spacing declaration
|
|
896
|
-
resolved hs2p read plan are skipped. Returns one
|
|
906
|
+
automatic — only ROIs whose sidecar has the same source-spacing declaration,
|
|
907
|
+
resolved hs2p read plan and feature identity are skipped. Returns one
|
|
897
908
|
:class:`~slide2vec.artifacts.DenseRegionArtifact` per input ROI.
|
|
898
909
|
|
|
899
910
|
The effective encoder input — the padded ROI for a whole-tile run, one
|
|
@@ -971,8 +982,9 @@ class Model:
|
|
|
971
982
|
to ``image_embeddings/<sample_id>.pt`` plus a provenance sidecar. The run splits its
|
|
972
983
|
images across all visible GPUs (``execution.num_gpus``); ``num_gpus=1`` encodes
|
|
973
984
|
fully in-process. Resume is automatic — images whose sidecar already exists are
|
|
974
|
-
skipped
|
|
975
|
-
image, in input
|
|
985
|
+
skipped, and a sidecar that records a different feature identity raises. Returns
|
|
986
|
+
one :class:`~slide2vec.artifacts.ImageEmbeddingArtifact` per input image, in input
|
|
987
|
+
order.
|
|
976
988
|
|
|
977
989
|
Unlike the pooled and dense paths there is no geometry to declare: the images are
|
|
978
990
|
heterogeneously sized (2048x1536 beside 96x96) and were never requested, so the
|
|
@@ -316,13 +316,15 @@ def _write_dense_grid(
|
|
|
316
316
|
) -> np.ndarray:
|
|
317
317
|
"""Publish one dense grid: payload atomically, then the sidecar. Returns the array.
|
|
318
318
|
|
|
319
|
-
The single write order every dense artifact follows (D6), whatever named it:
|
|
320
|
-
a temp file in the destination directory → ``os.replace``
|
|
321
|
-
filesystem) → then the ``.meta.json`` sidecar. A payload
|
|
322
|
-
therefore unambiguously means an incomplete unit, and resume
|
|
323
|
-
done-marker.
|
|
319
|
+
The single write order every dense artifact follows (D6), whatever named it: remove any
|
|
320
|
+
existing sidecar → payload to a temp file in the destination directory → ``os.replace``
|
|
321
|
+
into place (atomic on the same filesystem) → then the ``.meta.json`` sidecar. A payload
|
|
322
|
+
present without its sidecar therefore unambiguously means an incomplete unit, and resume
|
|
323
|
+
treats the sidecar as the done-marker. Removing the old sidecar first keeps a rewrite
|
|
324
|
+
interrupted between the two writes from pairing it with the new payload.
|
|
324
325
|
"""
|
|
325
326
|
grid_array = _ensure_array(grid)
|
|
327
|
+
metadata_path.unlink(missing_ok=True)
|
|
326
328
|
write_atomically(payload_path, lambda tmp_path: torch.save(_ensure_tensor(grid), tmp_path))
|
|
327
329
|
_write_metadata(metadata_path, metadata)
|
|
328
330
|
return grid_array
|
|
@@ -2,7 +2,7 @@ import argparse
|
|
|
2
2
|
|
|
3
3
|
from slide2vec.api import ExecutionOptions, Model, Pipeline, PreprocessingConfig
|
|
4
4
|
from slide2vec.progress import activate_progress_reporter, create_cli_progress_reporter
|
|
5
|
-
from slide2vec.utils.config import setup
|
|
5
|
+
from slide2vec.utils.config import setup
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def get_args_parser(add_help: bool = True):
|
|
@@ -24,7 +24,6 @@ def parse_args(argv=None):
|
|
|
24
24
|
|
|
25
25
|
def build_model_and_pipeline(args):
|
|
26
26
|
cfg, _cfg_path = setup(args)
|
|
27
|
-
hf_login()
|
|
28
27
|
model = Model.from_preset(
|
|
29
28
|
cfg.model.name,
|
|
30
29
|
output_variant=cfg.model.output_variant,
|
|
@@ -26,7 +26,7 @@ tiling:
|
|
|
26
26
|
read_coordinates_from: # path to an existing directory containing pre-extracted `.coordinates.npz` / `.coordinates.meta.json` artifacts to reuse instead of starting tiling from scratch
|
|
27
27
|
read_tiles_from: # path to an existing directory containing pre-extracted `.tiles.tar` tile stores to reuse instead of starting tiling from scratch
|
|
28
28
|
backend: "auto" # backend to use for slide reading; "auto" tries cucim -> vips -> openslide -> asap. Pin a backend for stable decoder selection across upgrades.
|
|
29
|
-
mask_backend: "auto" # backend for reading source masks (precomputed tissue / annotation), resolved independently from the mask path; "auto" probes openability like `backend`. Set explicitly (e.g. "openslide") when a mask needs a different decoder than its slide — hs2p
|
|
29
|
+
mask_backend: "auto" # backend for reading source masks (precomputed tissue / annotation), resolved independently from the mask path; "auto" probes openability like `backend`. Set explicitly (e.g. "openslide") when a mask needs a different decoder than its slide — hs2p never silently falls back. "auto" selects "tifffile" for TIFF masks whose samples are not 8-bit unsigned (e.g. 16-bit labels)
|
|
30
30
|
independent_sampling: true # selection strategy when annotation sampling is active. true: sample each class independently against its own binary mask (independent selection); false: sample once over the union of active classes, then post-filter per class by coverage (joint selection). Ignored when the masks vocabulary is left at the tissue-only default.
|
|
31
31
|
masks:
|
|
32
32
|
# Annotation-mask vocabulary forwarded to hs2p's sampling resolver. The shipped default
|
|
@@ -27,6 +27,7 @@ def get_args_parser(add_help: bool = True):
|
|
|
27
27
|
def main(argv=None) -> int:
|
|
28
28
|
from slide2vec.progress import emit_progress
|
|
29
29
|
from slide2vec.runtime.dense_shard import run_dense_shard
|
|
30
|
+
from slide2vec.runtime.feature_identity import dense_feature_identity
|
|
30
31
|
from slide2vec.runtime.dense_stage import (
|
|
31
32
|
region_specs_from_request,
|
|
32
33
|
resolve_output_torch_dtype,
|
|
@@ -68,6 +69,7 @@ def main(argv=None) -> int:
|
|
|
68
69
|
dense=dense,
|
|
69
70
|
batch_size=int(execution.batch_size),
|
|
70
71
|
device=loaded.device,
|
|
72
|
+
identity=dense_feature_identity(model, dense=dense, execution=execution),
|
|
71
73
|
precision=execution.precision,
|
|
72
74
|
output_dtype=resolve_output_torch_dtype(execution),
|
|
73
75
|
num_workers=execution.resolved_num_workers_per_gpu(),
|
|
@@ -55,6 +55,7 @@ def main(argv=None) -> int:
|
|
|
55
55
|
work_unit_shard_stem,
|
|
56
56
|
)
|
|
57
57
|
from slide2vec.runtime.embedding import tiling_result_annotation
|
|
58
|
+
from slide2vec.runtime.feature_identity import transform_record
|
|
58
59
|
|
|
59
60
|
load_successful_tiled_slides_fn = getattr(inference, "load_successful_tiled_slides", None)
|
|
60
61
|
if not callable(load_successful_tiled_slides_fn):
|
|
@@ -84,6 +85,8 @@ def main(argv=None) -> int:
|
|
|
84
85
|
shard_stem = work_unit_shard_stem(*decode_work_unit(work_unit))
|
|
85
86
|
slide, tiling_result = paired_by_unit[work_unit]
|
|
86
87
|
loaded = model._load_backend()
|
|
88
|
+
# The parent writes the sidecar without loading the encoder; hand it the record.
|
|
89
|
+
transform = transform_record(getattr(loaded, "transforms", None))
|
|
87
90
|
if is_hierarchical_preprocessing(preprocessing):
|
|
88
91
|
geometry = resolve_hierarchical_geometry(preprocessing, tiling_result)
|
|
89
92
|
index = build_hierarchical_index(
|
|
@@ -113,6 +116,7 @@ def main(argv=None) -> int:
|
|
|
113
116
|
"flat_index": torch.as_tensor(shard_indices, dtype=torch.long),
|
|
114
117
|
"tile_embeddings": tile_embeddings.detach().cpu() if torch.is_tensor(tile_embeddings) else torch.as_tensor(tile_embeddings),
|
|
115
118
|
"encoder_input_size_px": getattr(loaded, "encoder_input_size_px", None),
|
|
119
|
+
"transform": transform,
|
|
116
120
|
}
|
|
117
121
|
torch.save(payload, coordination_dir / f"{shard_stem}.hier.rank{global_rank}.pt")
|
|
118
122
|
else:
|
|
@@ -140,6 +144,7 @@ def main(argv=None) -> int:
|
|
|
140
144
|
"tile_index": torch.as_tensor(tile_indices, dtype=torch.long),
|
|
141
145
|
"tile_embeddings": tile_embeddings.detach().cpu() if torch.is_tensor(tile_embeddings) else torch.as_tensor(tile_embeddings),
|
|
142
146
|
"encoder_input_size_px": getattr(loaded, "encoder_input_size_px", None),
|
|
147
|
+
"transform": transform,
|
|
143
148
|
}
|
|
144
149
|
torch.save(payload, coordination_dir / f"{shard_stem}.tiles.rank{global_rank}.pt")
|
|
145
150
|
return 0
|
|
@@ -156,6 +161,7 @@ def main(argv=None) -> int:
|
|
|
156
161
|
"slide_embedding": _to_cpu_payload(embedded_slide.slide_embedding),
|
|
157
162
|
"latents": _to_cpu_payload(embedded_slide.latents),
|
|
158
163
|
"encoder_input_size_px": embedded_slide.encoder_input_size_px,
|
|
164
|
+
"transform": embedded_slide.transform,
|
|
159
165
|
}
|
|
160
166
|
# Stem by (sample_id, annotation) so two classes of one slide never overwrite each
|
|
161
167
|
# other; flat units keep the bare-sample_id filename for backward compatibility.
|
|
@@ -26,6 +26,7 @@ def get_args_parser(add_help: bool = True):
|
|
|
26
26
|
|
|
27
27
|
def main(argv=None) -> int:
|
|
28
28
|
from slide2vec.progress import emit_progress
|
|
29
|
+
from slide2vec.runtime.feature_identity import pooled_feature_identity
|
|
29
30
|
from slide2vec.runtime.image_shard import run_image_shard
|
|
30
31
|
from slide2vec.runtime.image_specs import image_specs_from_request
|
|
31
32
|
from slide2vec.runtime.model_settings import resolve_output_precision
|
|
@@ -60,6 +61,7 @@ def main(argv=None) -> int:
|
|
|
60
61
|
out_dir=output_dir,
|
|
61
62
|
batch_size=int(execution.batch_size),
|
|
62
63
|
output_precision=resolve_output_precision(execution.output_dtype, execution.precision),
|
|
64
|
+
identity=pooled_feature_identity(model, execution=execution),
|
|
63
65
|
output_format=execution.output_format,
|
|
64
66
|
precision=execution.precision,
|
|
65
67
|
num_workers=execution.resolved_image_num_workers_per_gpu(),
|
|
@@ -390,6 +390,20 @@ def attentions_tuple_to_grids(
|
|
|
390
390
|
return torch.cat(grids, dim=1)
|
|
391
391
|
|
|
392
392
|
|
|
393
|
+
class ProcessorTransform:
|
|
394
|
+
"""Apply a Hugging Face processor to one image.
|
|
395
|
+
|
|
396
|
+
A class rather than a closure so the processor stays readable: the sidecar's
|
|
397
|
+
transform record is read from it.
|
|
398
|
+
"""
|
|
399
|
+
|
|
400
|
+
def __init__(self, processor) -> None:
|
|
401
|
+
self.processor = processor
|
|
402
|
+
|
|
403
|
+
def __call__(self, image) -> Tensor:
|
|
404
|
+
return self.processor(images=image, return_tensors="pt")["pixel_values"].squeeze(0)
|
|
405
|
+
|
|
406
|
+
|
|
393
407
|
class Encoder(ABC):
|
|
394
408
|
"""Shared lifecycle contract for all encoders."""
|
|
395
409
|
|
|
@@ -527,6 +541,19 @@ class SlideEncoder(Encoder):
|
|
|
527
541
|
"""Pool tile-level features into a single slide-level embedding."""
|
|
528
542
|
...
|
|
529
543
|
|
|
544
|
+
def encode_slide_with_latents(
|
|
545
|
+
self,
|
|
546
|
+
tile_features: Tensor,
|
|
547
|
+
coordinates: Tensor | None = None,
|
|
548
|
+
*,
|
|
549
|
+
tile_size_lv0: int | None = None,
|
|
550
|
+
) -> tuple[Tensor, Tensor | None]:
|
|
551
|
+
"""Return the slide embedding and the encoder's latent representations.
|
|
552
|
+
|
|
553
|
+
Encoders that have latents (PRISM) override this; the default returns ``None``.
|
|
554
|
+
"""
|
|
555
|
+
return self.encode_slide(tile_features, coordinates, tile_size_lv0=tile_size_lv0), None
|
|
556
|
+
|
|
530
557
|
|
|
531
558
|
class PatientEncoder(Encoder):
|
|
532
559
|
"""Base class for encoders that aggregate slide embeddings into patient embeddings."""
|
|
@@ -16,9 +16,17 @@ Structurally it is a plain :class:`TimmTileEncoder` (mirroring ``lunit`` /
|
|
|
16
16
|
``prost40m`` / ``uni``): the dense (``encode_tiles_dense``) and attention
|
|
17
17
|
(``encode_tiles_attention``) paths are inherited unchanged from the timm ViT
|
|
18
18
|
base, so the control is dense-extraction- and attention-capable exactly like the
|
|
19
|
-
pathology encoders. ``dynamic_img_size=True`` lets the
|
|
20
|
-
run at
|
|
21
|
-
|
|
19
|
+
pathology encoders. ``dynamic_img_size=True`` lets the natively 518px backbone
|
|
20
|
+
run at other patch-aligned sizes via positional-embedding interpolation.
|
|
21
|
+
|
|
22
|
+
Input size follows Meta's DINOv2 evaluation recipe
|
|
23
|
+
(``make_classification_eval_transform``: bicubic Resize 256 -> CenterCrop 224
|
|
24
|
+
-> ImageNet normalization), not timm's 518px checkpoint config. The registry
|
|
25
|
+
``input_size`` is 224, the size the encoder sees; 256 would make declared runs
|
|
26
|
+
encode 256px. Declared pooled runs read and encode 224px tiles with
|
|
27
|
+
normalization only (112 µm at the default 0.5 µm/px, 16x16 tokens). Native
|
|
28
|
+
518px is an explicit request with ``allow_non_recommended_settings=True``.
|
|
29
|
+
Given pre-cropped tiles use Meta's Resize 256 -> CenterCrop 224 recipe.
|
|
22
30
|
|
|
23
31
|
Spacing note: a natural-image model has **no** intrinsic micron-per-pixel
|
|
24
32
|
spacing, so it declares ``supported_spacing_um=None`` — it is *spacing-agnostic*
|
|
@@ -26,15 +34,17 @@ and :func:`validate_encoder_config` never rejects a requested spacing for it
|
|
|
26
34
|
(unlike the pathology encoders, which are validated at a specific spacing). It
|
|
27
35
|
still needs *a* spacing to tile a slide, so ``default_spacing_um=0.5`` sets the
|
|
28
36
|
tiling default: 0.5 µm/px is the task-spacing the pathology tile encoders
|
|
29
|
-
declare.
|
|
30
|
-
normalization only: 518px by default, or 224px for matched-resolution
|
|
31
|
-
experiments when requested explicitly with ``allow_non_recommended_settings=True``.
|
|
32
|
-
Given pre-cropped tiles still use the shipped Resize 518 -> CenterCrop 518
|
|
33
|
-
transform. Because it is agnostic, sweeping other task-spacings (e.g. 0.25)
|
|
37
|
+
declare. Because it is agnostic, sweeping other task-spacings (e.g. 0.25)
|
|
34
38
|
needs no ``allow_non_recommended_settings`` escape hatch — any requested spacing
|
|
35
39
|
is accepted as-is.
|
|
36
40
|
"""
|
|
37
41
|
|
|
42
|
+
from typing import Callable
|
|
43
|
+
|
|
44
|
+
import torch
|
|
45
|
+
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
|
|
46
|
+
from torchvision.transforms import v2
|
|
47
|
+
|
|
38
48
|
from slide2vec.encoders.base import TimmTileEncoder
|
|
39
49
|
from slide2vec.encoders.registry import register_encoder
|
|
40
50
|
|
|
@@ -43,7 +53,7 @@ from slide2vec.encoders.registry import register_encoder
|
|
|
43
53
|
"dinov2-vitb14",
|
|
44
54
|
output_variants={"default": {"encode_dim": 768}},
|
|
45
55
|
default_output_variant="default",
|
|
46
|
-
input_size=
|
|
56
|
+
input_size=224,
|
|
47
57
|
supports_variable_input_size=True,
|
|
48
58
|
patch_size=14,
|
|
49
59
|
supported_spacing_um=None, # spacing-agnostic: no intrinsic µm/px, so no validation constraint
|
|
@@ -56,5 +66,17 @@ class DINOv2ViTB14(TimmTileEncoder):
|
|
|
56
66
|
super().__init__(
|
|
57
67
|
"vit_base_patch14_dinov2.lvd142m",
|
|
58
68
|
output_variant=output_variant,
|
|
59
|
-
dynamic_img_size=True, #
|
|
69
|
+
dynamic_img_size=True, # 224 default, 518 opt-in and dense sizes; no-op at native 518
|
|
60
70
|
)
|
|
71
|
+
|
|
72
|
+
def get_transform(self) -> Callable:
|
|
73
|
+
# Meta's DINOv2 eval recipe for given pre-cropped images; timm's packaged
|
|
74
|
+
# pretrained_cfg would instead Resize 518 -> CenterCrop 518. Declared runs
|
|
75
|
+
# use get_normalization_transform() and encode exactly the requested size.
|
|
76
|
+
return v2.Compose([
|
|
77
|
+
v2.ToImage(),
|
|
78
|
+
v2.Resize(256, interpolation=v2.InterpolationMode.BICUBIC, antialias=True),
|
|
79
|
+
v2.CenterCrop(224),
|
|
80
|
+
v2.ToDtype(torch.float32, scale=True),
|
|
81
|
+
v2.Normalize(mean=IMAGENET_DEFAULT_MEAN, std=IMAGENET_DEFAULT_STD),
|
|
82
|
+
])
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from typing import Callable
|
|
4
4
|
|
|
5
5
|
import torch
|
|
6
|
+
from huggingface_hub import hf_hub_download
|
|
7
|
+
from huggingface_hub.errors import LocalEntryNotFoundError
|
|
6
8
|
from torchvision.transforms import v2
|
|
7
9
|
|
|
8
10
|
from slide2vec.encoders.base import (
|
|
@@ -13,6 +15,18 @@ from slide2vec.encoders.base import (
|
|
|
13
15
|
)
|
|
14
16
|
from slide2vec.encoders.registry import register_encoder
|
|
15
17
|
|
|
18
|
+
_HF_REPO_ID = "prov-gigapath/prov-gigapath"
|
|
19
|
+
_HF_SLIDE_CHECKPOINT = "slide_encoder.pth"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _slide_checkpoint_path() -> str:
|
|
23
|
+
# A default hf_hub_download queries the Hub on every call, even when cached.
|
|
24
|
+
try:
|
|
25
|
+
return hf_hub_download(repo_id=_HF_REPO_ID, filename=_HF_SLIDE_CHECKPOINT, local_files_only=True)
|
|
26
|
+
except LocalEntryNotFoundError:
|
|
27
|
+
return hf_hub_download(repo_id=_HF_REPO_ID, filename=_HF_SLIDE_CHECKPOINT)
|
|
28
|
+
|
|
29
|
+
|
|
16
30
|
# Prov-GigaPath model card transform (given pre-cropped images only): resize to 256,
|
|
17
31
|
# center-crop to the model's native 224, ImageNet normalization. timm's packaged
|
|
18
32
|
# pretrained_cfg reports crop_pct=1.0 -> the timm default would instead Resize(224),
|
|
@@ -38,12 +52,12 @@ _GIGAPATH_STD = (0.229, 0.224, 0.225)
|
|
|
38
52
|
patch_size=16,
|
|
39
53
|
supported_spacing_um=0.5,
|
|
40
54
|
precision="fp16",
|
|
41
|
-
source=
|
|
55
|
+
source=_HF_REPO_ID,
|
|
42
56
|
)
|
|
43
57
|
class GigaPath(TimmTileEncoder):
|
|
44
58
|
def __init__(self, *, output_variant: str | None = None):
|
|
45
59
|
super().__init__(
|
|
46
|
-
"hf_hub:
|
|
60
|
+
f"hf_hub:{_HF_REPO_ID}",
|
|
47
61
|
output_variant=output_variant,
|
|
48
62
|
dynamic_img_size=True,
|
|
49
63
|
)
|
|
@@ -70,17 +84,17 @@ class GigaPath(TimmTileEncoder):
|
|
|
70
84
|
default_output_variant="default",
|
|
71
85
|
supported_spacing_um=0.5,
|
|
72
86
|
precision="fp16",
|
|
73
|
-
source=
|
|
87
|
+
source=_HF_REPO_ID,
|
|
74
88
|
)
|
|
75
89
|
class GigaPathSlideEncoder(SlideEncoder):
|
|
76
90
|
def __init__(self, *, output_variant: str | None = None):
|
|
77
91
|
from gigapath.slide_encoder import create_model
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
93
|
+
# create_model given an "hf_hub:" name force-downloads into ~/.cache/ on every
|
|
94
|
+
# load, ignoring HF_HOME; a local path skips that download.
|
|
95
|
+
checkpoint_path = _slide_checkpoint_path()
|
|
96
|
+
# create_model returns the module in training mode (dropout and drop-path active).
|
|
97
|
+
self._model = create_model(checkpoint_path, "gigapath_slide_enc12l768d", 1536).eval()
|
|
84
98
|
self._device = preferred_default_device()
|
|
85
99
|
self._output_variant = resolve_requested_output_variant(output_variant)
|
|
86
100
|
|
|
@@ -84,6 +84,7 @@ from torchvision.transforms import v2
|
|
|
84
84
|
from transformers import AutoProcessor, CLIPConfig, CLIPModel
|
|
85
85
|
|
|
86
86
|
from slide2vec.encoders.base import (
|
|
87
|
+
ProcessorTransform,
|
|
87
88
|
TileEncoder,
|
|
88
89
|
attentions_tuple_to_grids,
|
|
89
90
|
hf_eager_attention,
|
|
@@ -190,12 +191,7 @@ class ISight(TileEncoder):
|
|
|
190
191
|
bicubic resize to 336, a 336 center crop, and OpenAI CLIP
|
|
191
192
|
mean/std — the resize and crop are no-ops on tiles already cut at 336.
|
|
192
193
|
"""
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
def transform(image):
|
|
196
|
-
return processor(images=image, return_tensors="pt")["pixel_values"].squeeze(0)
|
|
197
|
-
|
|
198
|
-
return transform
|
|
194
|
+
return ProcessorTransform(AutoProcessor.from_pretrained(_BASE_MODEL))
|
|
199
195
|
|
|
200
196
|
def get_normalization_transform(self) -> Callable:
|
|
201
197
|
image_processor = AutoProcessor.from_pretrained(_BASE_MODEL).image_processor
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Lunit ViT-S/8 tile encoder implementation.
|
|
2
|
+
|
|
3
|
+
The ``1aurent`` hub ``config.json`` carries timm's stock ``vit_small_patch8_224.dino``
|
|
4
|
+
data config (ImageNet mean/std, crop_pct 0.9). Lunit publishes no transform, so the
|
|
5
|
+
geometry keeps that config (``Resize(248)`` -> ``CenterCrop(224)``), but both
|
|
6
|
+
transforms normalize with Lunit's ViT-S training stats, as documented by kaiko-ai/eva
|
|
7
|
+
(https://github.com/kaiko-ai/eva/blob/main/src/eva/vision/models/networks/backbones/pathology/lunit.py).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Callable
|
|
11
|
+
|
|
12
|
+
import torch
|
|
13
|
+
from torchvision import transforms
|
|
14
|
+
from torchvision.transforms import v2
|
|
15
|
+
|
|
16
|
+
from slide2vec.encoders.base import TimmTileEncoder
|
|
17
|
+
from slide2vec.encoders.registry import register_encoder
|
|
18
|
+
|
|
19
|
+
_LUNIT_MEAN = (0.70322989, 0.53606487, 0.66096631)
|
|
20
|
+
_LUNIT_STD = (0.21716536, 0.26081574, 0.20723464)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@register_encoder(
|
|
24
|
+
"lunit",
|
|
25
|
+
output_variants={"default": {"encode_dim": 384}},
|
|
26
|
+
default_output_variant="default",
|
|
27
|
+
input_size=224,
|
|
28
|
+
supports_variable_input_size=True,
|
|
29
|
+
patch_size=8,
|
|
30
|
+
supported_spacing_um=0.5,
|
|
31
|
+
precision="fp32",
|
|
32
|
+
source="1aurent/vit_small_patch8_224.lunit_dino",
|
|
33
|
+
)
|
|
34
|
+
class LunitTileEncoder(TimmTileEncoder):
|
|
35
|
+
def __init__(self, *, output_variant: str | None = None):
|
|
36
|
+
super().__init__(
|
|
37
|
+
"hf_hub:1aurent/vit_small_patch8_224.lunit_dino",
|
|
38
|
+
output_variant=output_variant,
|
|
39
|
+
dynamic_img_size=True, # enable dense extraction; no-op at native size
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def get_transform(self) -> Callable:
|
|
43
|
+
return transforms.Compose([
|
|
44
|
+
transforms.Resize(248, interpolation=transforms.InterpolationMode.BICUBIC),
|
|
45
|
+
transforms.CenterCrop(224),
|
|
46
|
+
transforms.ToTensor(),
|
|
47
|
+
transforms.Normalize(mean=_LUNIT_MEAN, std=_LUNIT_STD),
|
|
48
|
+
])
|
|
49
|
+
|
|
50
|
+
def get_normalization_transform(self) -> Callable:
|
|
51
|
+
return v2.Compose([
|
|
52
|
+
v2.ToImage(),
|
|
53
|
+
v2.ToDtype(torch.float32, scale=True),
|
|
54
|
+
v2.Normalize(mean=_LUNIT_MEAN, std=_LUNIT_STD),
|
|
55
|
+
])
|