diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 465b0c3b8..9faabb796 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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 @@ -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 @@ -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 @@ -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' diff --git a/tests/models/test_arch_mapde.py b/tests/models/test_arch_mapde.py index c4f40be9e..19163f593 100644 --- a/tests/models/test_arch_mapde.py +++ b/tests/models/test_arch_mapde.py @@ -1,6 +1,7 @@ """Unit test package for SCCNN.""" from collections.abc import Callable +from pathlib import Path import numpy as np import torch @@ -14,7 +15,7 @@ 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) @@ -22,7 +23,7 @@ def _load_mapde(name: str) -> MapDe: 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: @@ -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: diff --git a/tests/models/test_arch_micronet.py b/tests/models/test_arch_micronet.py index 2012aeb4e..07064db1b 100644 --- a/tests/models/test_arch_micronet.py +++ b/tests/models/test_arch_micronet.py @@ -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: diff --git a/tests/models/test_hovernet.py b/tests/models/test_hovernet.py index 34ddab2c2..aeb003721 100644 --- a/tests/models/test_hovernet.py +++ b/tests/models/test_hovernet.py @@ -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), @@ -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: