From b2ef3d9420ed75facfdc979d3f5bbb91317d2cf8 Mon Sep 17 00:00:00 2001 From: clemsgrs Date: Mon, 5 Jan 2026 10:21:07 +0000 Subject: [PATCH 1/3] sync hs2p --- slide2vec/hs2p | 2 +- slide2vec/utils/__init__.py | 1 - slide2vec/utils/utils.py | 15 --------------- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/slide2vec/hs2p b/slide2vec/hs2p index bfa3bf8..98b5c95 160000 --- a/slide2vec/hs2p +++ b/slide2vec/hs2p @@ -1 +1 @@ -Subproject commit bfa3bf871671548da2824ea06b21c4d9e96b5150 +Subproject commit 98b5c95c61d725a89152b2a68c8f8566eb6bae9c diff --git a/slide2vec/utils/__init__.py b/slide2vec/utils/__init__.py index 3395b9d..976cdbe 100644 --- a/slide2vec/utils/__init__.py +++ b/slide2vec/utils/__init__.py @@ -2,7 +2,6 @@ initialize_wandb, fix_random_seeds, get_sha, - load_csv, update_state_dict, ) from .log_utils import setup_logging diff --git a/slide2vec/utils/utils.py b/slide2vec/utils/utils.py index c645e10..3f6b7be 100644 --- a/slide2vec/utils/utils.py +++ b/slide2vec/utils/utils.py @@ -111,21 +111,6 @@ def initialize_wandb( return run -def load_csv(cfg): - df = pd.read_csv(cfg.csv) - if "wsi_path" in df.columns: - wsi_paths = [Path(x) for x in df.wsi_path.values.tolist()] - elif "slide_path" in df.columns: - wsi_paths = [Path(x) for x in df.slide_path.values.tolist()] - if "mask_path" in df.columns: - mask_paths = [Path(x) for x in df.mask_path.values.tolist()] - elif "segmentation_mask_path" in df.columns: - mask_paths = [Path(x) for x in df.segmentation_mask_path.values.tolist()] - else: - mask_paths = [None for _ in wsi_paths] - return wsi_paths, mask_paths - - def update_state_dict( *, model_dict: dict, From 21cf5e5e538b695bf69238c607eeb9478b974d2e Mon Sep 17 00:00:00 2001 From: clemsgrs Date: Mon, 5 Jan 2026 17:29:42 +0000 Subject: [PATCH 2/3] improve DINO ViT models loading --- slide2vec/configs/default_model.yaml | 1 + slide2vec/models/models.py | 28 ++++++++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/slide2vec/configs/default_model.yaml b/slide2vec/configs/default_model.yaml index faea47a..83fab15 100644 --- a/slide2vec/configs/default_model.yaml +++ b/slide2vec/configs/default_model.yaml @@ -16,6 +16,7 @@ model: tile_size: ${tiling.params.tile_size} restrict_to_tissue: false # whether to restrict tile content to tissue pixels only when feeding tile through encoder patch_size: 256 # if level is "region", size used to unroll the region into patches + token_size: 16 # size of the tokens used model is a custom pretrained ViT save_tile_embeddings: false # whether to save tile embeddings alongside the pooled slide embedding when level is "slide" save_latents: false # whether to save the latent representations from the model alongside the slide embedding (only supported for 'prism') diff --git a/slide2vec/models/models.py b/slide2vec/models/models.py index cc72a9c..925473f 100644 --- a/slide2vec/models/models.py +++ b/slide2vec/models/models.py @@ -13,7 +13,6 @@ from timm.data.transforms_factory import create_transform from conch.open_clip_custom import create_model_from_pretrained -from musk import modeling as musk_modeling from musk import utils as musk_utils import slide2vec.distributed as distributed @@ -70,11 +69,12 @@ def __init__( pretrained_weights=options.pretrained_weights, input_size=options.tile_size, ) - elif options.name is None and options.arch: + elif options.name == "dino" and options.arch: model = DINOViT( arch=options.arch, pretrained_weights=options.pretrained_weights, input_size=options.tile_size, + patch_size=options.token_size, ) elif options.level == "region": if options.name == "virchow": @@ -282,21 +282,13 @@ def build_encoder(self): return encoder def get_transforms(self): - if self.input_size > 224: - transform = transforms.Compose( - [ - MaybeToTensor(), - transforms.CenterCrop(224), - make_normalize_transform(), - ] - ) - else: - transforms.Compose( - [ - MaybeToTensor(), - make_normalize_transform(), - ] - ) + transform = transforms.Compose( + [ + MaybeToTensor(), + transforms.CenterCrop(self.input_size), + make_normalize_transform(), + ] + ) return transform def forward(self, x): @@ -344,7 +336,7 @@ def __init__( def load_weights(self): if distributed.is_main_process(): print(f"Loading pretrained weights from: {self.pretrained_weights}") - state_dict = torch.load(self.pretrained_weights, map_location="cpu") + state_dict = torch.load(self.pretrained_weights, map_location="cpu", weights_only=False) if self.ckpt_key: state_dict = state_dict[self.ckpt_key] nn.modules.utils.consume_prefix_in_state_dict_if_present( From b196aa1fc12b876666d221db9c420cfacdc3db9c Mon Sep 17 00:00:00 2001 From: clemsgrs Date: Mon, 5 Jan 2026 17:30:04 +0000 Subject: [PATCH 3/3] fix different numpy version related error --- slide2vec/models/models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/slide2vec/models/models.py b/slide2vec/models/models.py index 925473f..bb94ba5 100644 --- a/slide2vec/models/models.py +++ b/slide2vec/models/models.py @@ -259,7 +259,17 @@ def __init__( def load_weights(self): if distributed.is_main_process(): print(f"Loading pretrained weights from: {self.pretrained_weights}") - state_dict = torch.load(self.pretrained_weights, map_location="cpu") + + # Fix for loading checkpoints saved with numpy 2.0+ in an environment with numpy < 2.0 + try: + import numpy._core + except ImportError: + import numpy as np + import sys + sys.modules["numpy._core"] = np.core + sys.modules["numpy._core.multiarray"] = np.core.multiarray + + state_dict = torch.load(self.pretrained_weights, map_location="cpu", weights_only=False) if self.ckpt_key: state_dict = state_dict[self.ckpt_key] nn.modules.utils.consume_prefix_in_state_dict_if_present(