Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -33,7 +33,7 @@ jobs:
python -m pip install ruff==0.13.3 pytest pytest-cov pytest-runner
pip install -r requirements/requirements.txt
- name: Cache tiatoolbox static assets
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: tiatoolbox-home-static
path: ~/.tiatoolbox
Expand Down Expand Up @@ -76,6 +76,17 @@ jobs:
coverage-file: coverage.xml
dsn: ${{ secrets.DEEPSOURCE_DSN }}
fail-ci-on-error: false
- name: List tiatoolbox contents
run: ls -lahR ~/.tiatoolbox
- name: Delete Hugging Face cache for large models
run: |
find ~/.tiatoolbox/models -type f -size +250M -exec bash -c '
for model_path; do
model_name=$(basename "$model_path")
cache_dir="$HOME/.tiatoolbox/models/.cache/huggingface/download"
rm -vf "$cache_dir/${model_name}.lock" "$cache_dir/${model_name}.metadata"
done
' bash {} +

release:
runs-on: ubuntu-24.04
Expand All @@ -84,10 +95,10 @@ jobs:
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/pre-release' || startsWith(github.ref, 'refs/tags/v')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
Expand Down
8 changes: 5 additions & 3 deletions tests/models/test_arch_mapde.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit test package for SCCNN."""

from collections.abc import Callable
from pathlib import Path

import numpy as np
import torch
Expand All @@ -14,15 +15,15 @@
ON_GPU = toolbox_env.has_gpu()


def _load_mapde(name: str) -> MapDe:
def _load_mapde(name: str) -> tuple[MapDe, str]:
"""Loads MapDe model with specified weights."""
model = MapDe()
weights_path = fetch_pretrained_weights(name)
map_location = select_device(on_gpu=ON_GPU)
pretrained = torch.load(weights_path, map_location=map_location)
model.load_state_dict(pretrained)
model.to(map_location)
return model
return model, weights_path


def test_functionality(remote_sample: Callable) -> None:
Expand All @@ -42,12 +43,13 @@ def test_functionality(remote_sample: Callable) -> None:
coord_space="resolution",
)

model = _load_mapde(name="mapde-conic")
model, weights_path = _load_mapde(name="mapde-conic")
patch = model.preproc(patch)
batch = torch.from_numpy(patch)[None]
output = model.infer_batch(model, batch, device=select_device(on_gpu=ON_GPU))
output = model.postproc(output[0])
assert np.all(output[0:2] == [[19, 171], [53, 89]])
Path(weights_path).unlink()


def test_multiclass_output() -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/models/test_arch_micronet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_functionality(
output = model.infer_batch(model, batch, device=map_location)
output, _ = model.postproc(output[0])
assert np.max(np.unique(output)) == 46
Path(weights_path).unlink()


def test_value_error() -> None:
Expand Down
36 changes: 1 addition & 35 deletions tests/models/test_hovernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ def test_functionality(remote_sample: Callable) -> None:
output = model.postproc(output)
assert len(output[1]) > 0, "Must have some nuclei."

# * test fast mode (architecture used for MoNuSAC data)
patch = reader.read_bounds(
(0, 0, 256, 256),
resolution=0.25,
units="mpp",
coord_space="resolution",
)
batch = torch.from_numpy(patch)[None]
model = HoVerNet(num_types=5, mode="fast")
weights_path = fetch_pretrained_weights("hovernet_fast-monusac")
pretrained = torch.load(weights_path)
model.load_state_dict(pretrained)
output = model.infer_batch(model, batch, device=select_device(on_gpu=False))
output = [v[0] for v in output]
output = model.postproc(output)
assert len(output[1]) > 0, "Must have some nuclei."

# * test original mode on CoNSeP dataset (architecture used in HoVerNet paper)
patch = reader.read_bounds(
(0, 0, 270, 270),
Expand All @@ -74,26 +57,9 @@ def test_functionality(remote_sample: Callable) -> None:
output = model.postproc(output)
assert len(output[1]) > 0, "Must have some nuclei."

# * test original mode on Kumar dataset (architecture used in HoVerNet paper)
patch = reader.read_bounds(
(0, 0, 270, 270),
resolution=0.25,
units="mpp",
coord_space="resolution",
)
batch = torch.from_numpy(patch)[None]
model = HoVerNet(num_types=None, mode="original")
weights_path = fetch_pretrained_weights("hovernet_original-kumar")
pretrained = torch.load(weights_path)
model.load_state_dict(pretrained)
output = model.infer_batch(model, batch, device=select_device(on_gpu=False))
output = [v[0] for v in output]
output = model.postproc(output)
assert len(output[1]) > 0, "Must have some nuclei."

# test crash when providing exotic mode
with pytest.raises(ValueError, match=r".*Invalid mode.*"):
model = HoVerNet(num_types=None, mode="super")
_ = HoVerNet(num_types=None, mode="super")


def test_unit_blocks() -> None:
Expand Down