Skip to content

Commit 78af2f2

Browse files
authored
Merge pull request #107 from KatherLab/v2.3
- change project version - add version check on both mlp and vision models - add version check on heatmaps - update example checkpoint used in tests
2 parents 54ffcd7 + 6915d8b commit 78af2f2

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "stamp"
3-
version = "2.2.0"
3+
version = "2.3.0"
44
authors = [
55
{ name = "Omar El Nahhas", email = "omar.el_nahhas@tu-dresden.de" },
66
{ name = "Marko van Treeck", email = "markovantreeck@gmail.com" },

src/stamp/heatmaps/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from stamp.preprocessing import supported_extensions
2323
from stamp.preprocessing.tiling import get_slide_mpp_
2424
from stamp.types import DeviceLikeType, Microns, SlideMPP, TilePixels
25+
from packaging.version import Version
26+
2527

2628
_logger = logging.getLogger("stamp")
2729

@@ -168,8 +170,6 @@ def heatmaps_(
168170
topk: int,
169171
bottomk: int,
170172
) -> None:
171-
model = LitVisionTransformer.load_from_checkpoint(checkpoint_path).to(device).eval()
172-
173173
# Collect slides to generate heatmaps for
174174
if slide_paths is not None:
175175
wsis_to_process = (wsi_dir / slide for slide in slide_paths)
@@ -227,6 +227,17 @@ def heatmaps_(
227227
# coordinates as used by OpenSlide
228228
coords_tile_slide_px = torch.round(coords_um / slide_mpp).long()
229229

230+
model = (
231+
LitVisionTransformer.load_from_checkpoint(checkpoint_path).to(device).eval()
232+
)
233+
234+
# TODO: Update version when a newer model logic breaks heatmaps.
235+
if Version(model.stamp_version) < Version("2.3.0"):
236+
raise ValueError(
237+
f"model has been built with stamp version {model.stamp_version} "
238+
f"which is incompatible with the current version."
239+
)
240+
230241
# Score for the entire slide
231242
slide_score = (
232243
model.vision_transformer(

src/stamp/modeling/lightning_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ def __init__(
114114
self.categories = np.array(categories)
115115
self.train_patients = train_patients
116116
self.valid_patients = valid_patients
117+
self.stamp_version = str(stamp_version)
117118

118119
_ = metadata # unused, but saved in model
119120

120121
# Check if version is compatible.
121122
# This should only happen when the model is loaded,
122123
# otherwise the default value will make these checks pass.
123124
# TODO: Change this on version change
124-
if stamp_version < Version("2.0.0.dev8"):
125+
if stamp_version < Version("2.3.0"):
125126
# Update this as we change our model in incompatible ways!
126127
raise ValueError(
127128
f"model has been built with stamp version {stamp_version} "

src/stamp/modeling/mlp_classifier.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,26 @@ def __init__(
8383
self.total_steps = total_steps
8484
self.max_lr = max_lr
8585
self.div_factor = div_factor
86-
87-
# TODO: Add version check with version 2.2.1, for both MLP and Transformer
86+
self.stamp_version = str(stamp_version)
87+
88+
# Check if version is compatible.
89+
# This should only happen when the model is loaded,
90+
# otherwise the default value will make these checks pass.
91+
# TODO: Change this on version change
92+
if stamp_version < Version("2.3.0"):
93+
# Update this as we change our model in incompatible ways!
94+
raise ValueError(
95+
f"model has been built with stamp version {stamp_version} "
96+
f"which is incompatible with the current version."
97+
)
98+
elif stamp_version > Version(stamp.__version__):
99+
# Let's be strict with models "from the future",
100+
# better fail deadly than have broken results.
101+
raise ValueError(
102+
"model has been built with a stamp version newer than the installed one "
103+
f"({stamp_version} > {stamp.__version__}). "
104+
"Please upgrade stamp to a compatible version."
105+
)
88106

89107
def forward(self, x: Tensor) -> Tensor:
90108
return self.model(x)

tests/test_deployment_backward_compatibility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
)
1414
def test_backwards_compatibility() -> None:
1515
example_checkpoint_path = download_file(
16-
url="https://github.com/KatherLab/STAMP/releases/download/2.2.0/example-model.ckpt",
17-
file_name="example-modelv2_3.ckpt",
18-
sha256sum="1caa5b56a02d09e6df72f087ebe9f87bae4e53de0516e2291e6dd1ce7dfff054",
16+
url="https://github.com/KatherLab/STAMP/releases/download/2.2.0/example-model-v2_3_0.ckpt",
17+
file_name="example-modelv2_3_0.ckpt",
18+
sha256sum="eb6225fcdea7f33dee80fd5dc4e7a0da6cd0d91a758e3ee9605d6869b30ab657",
1919
)
2020
example_feature_path = download_file(
2121
url="https://github.com/KatherLab/STAMP/releases/download/2.2.0/TCGA-AA-3877-01Z-00-DX1.36902310-bc0b-4437-9f86-6df85703e0ad.h5",

tests/test_heatmaps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
@pytest.mark.filterwarnings("ignore:There is a performance drop")
1111
def test_heatmap_integration(tmp_path: Path) -> None:
1212
example_checkpoint_path = download_file(
13-
url="https://github.com/KatherLab/STAMP/releases/download/2.2.0/example-model.ckpt",
14-
file_name="example-modelv2_3.ckpt",
15-
sha256sum="1caa5b56a02d09e6df72f087ebe9f87bae4e53de0516e2291e6dd1ce7dfff054",
13+
url="https://github.com/KatherLab/STAMP/releases/download/2.2.0/example-model-v2_3_0.ckpt",
14+
file_name="example-modelv2_3_0.ckpt",
15+
sha256sum="eb6225fcdea7f33dee80fd5dc4e7a0da6cd0d91a758e3ee9605d6869b30ab657",
1616
)
1717
example_slide_path = download_file(
1818
url="https://github.com/KatherLab/STAMP/releases/download/2.0.0.dev14/TCGA-G4-6625-01Z-00-DX1.0fa26667-2581-4f96-a891-d78dbc3299b4.svs",

0 commit comments

Comments
 (0)