From 3e10af2299998fe9e2e3e5072294bc08ffebb6c1 Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Mon, 13 Jan 2025 16:34:45 +0100 Subject: [PATCH 1/8] Bump version to 1.4.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 040a55e..3b94eba 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='torchstain', - version='1.4.0', + version='1.4.1', description='Stain normalization tools for histological analysis and computational pathology', long_description=README, long_description_content_type='text/markdown', From 90be62c15b9e65b2c9efb061474cfafe665bbc2e Mon Sep 17 00:00:00 2001 From: Samir Moustafa <31715540+SamirMoustafa@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:45:37 +0300 Subject: [PATCH 2/8] Adapt rgb2lab to handle device-specific (GPU) tensors Moved constant tensors to the same device as input for rgb2lab function. --- torchstain/torch/utils/rgb2lab.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/torchstain/torch/utils/rgb2lab.py b/torchstain/torch/utils/rgb2lab.py index bbb0d56..a765fc5 100644 --- a/torchstain/torch/utils/rgb2lab.py +++ b/torchstain/torch/utils/rgb2lab.py @@ -9,17 +9,21 @@ def rgb2lab(rgb): arr = rgb.type(torch.float32) - + # Move constant tensors to the same device as input + device = arr.device + _rgb2xyz_device = _rgb2xyz.to(device) + _white_device = _white.to(device) + # convert rgb -> xyz color domain mask = arr > 0.04045 not_mask = torch.logical_not(mask) arr.masked_scatter_(mask, torch.pow((torch.masked_select(arr, mask) + 0.055) / 1.055, 2.4)) arr.masked_scatter_(not_mask, torch.masked_select(arr, not_mask) / 12.92) - xyz = torch.tensordot(torch.t(_rgb2xyz), arr, dims=([0], [0])) + xyz = torch.tensordot(torch.t(_rgb2xyz_device), arr, dims=([0], [0])) # scale by CIE XYZ tristimulus values of the reference white point - arr = torch.mul(xyz, 1 / _white.type(xyz.dtype).unsqueeze(dim=-1).unsqueeze(dim=-1)) + arr = torch.mul(xyz, 1 / _white_device.type(xyz.dtype).unsqueeze(dim=-1).unsqueeze(dim=-1)) # nonlinear distortion and linear transformation mask = arr > 0.008856 From 8fd12ce1960d9811267518f0163044e527a2512f Mon Sep 17 00:00:00 2001 From: Samir Moustafa <31715540+SamirMoustafa@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:53:35 +0300 Subject: [PATCH 3/8] Ensure constant tensors are on the correct device (GPU) Moved constant tensors to the same device as input for compatibility. --- torchstain/torch/utils/lab2rgb.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/torchstain/torch/utils/lab2rgb.py b/torchstain/torch/utils/lab2rgb.py index 250c1c9..309632d 100644 --- a/torchstain/torch/utils/lab2rgb.py +++ b/torchstain/torch/utils/lab2rgb.py @@ -6,6 +6,11 @@ def lab2rgb(lab): lab = lab.type(torch.float32) + # Move constant tensors to the same device as input + device = lab.device + _white_device = _white.to(device) + _xyz2rgb_device = _xyz2rgb.to(device) + # rescale back from OpenCV format and extract LAB channel L, a, b = lab[0] / 2.55, lab[1] - 128, lab[2] - 128 @@ -24,10 +29,10 @@ def lab2rgb(lab): out.masked_scatter_(not_mask, (torch.masked_select(out, not_mask) - 16 / 116) / 7.787) # rescale to the reference white (illuminant) - out = torch.mul(out, _white.type(out.dtype).unsqueeze(dim=-1).unsqueeze(dim=-1)) + out = torch.mul(out, _white_device.type(out.dtype).unsqueeze(dim=-1).unsqueeze(dim=-1)) # convert XYZ -> RGB color domain - arr = torch.tensordot(out, torch.t(_xyz2rgb).type(out.dtype), dims=([0], [0])) + arr = torch.tensordot(out, torch.t(_xyz2rgb_device).type(out.dtype), dims=([0], [0])) mask = arr > 0.0031308 not_mask = torch.logical_not(mask) arr.masked_scatter_(mask, 1.055 * torch.pow(torch.masked_select(arr, mask), 1 / 2.4) - 0.055) From b644070520bb920c980d930de64463808c93c109 Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Tue, 28 Oct 2025 18:52:08 +0100 Subject: [PATCH 4/8] update to ubuntu-24.04 runners --- .github/workflows/build.yaml | 4 ++-- .github/workflows/tests_full.yml | 6 +++--- .github/workflows/tests_quick.yml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 26f9a9a..f50327f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,7 +6,7 @@ on: jobs: build_wheels: name: Build release - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 @@ -26,7 +26,7 @@ jobs: upload_pypi: needs: build_wheels - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') diff --git a/.github/workflows/tests_full.yml b/.github/workflows/tests_full.yml index 057d00f..148adf5 100644 --- a/.github/workflows/tests_full.yml +++ b/.github/workflows/tests_full.yml @@ -11,7 +11,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 if: startsWith(github.ref, 'refs/tags/v') != true @@ -40,7 +40,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2019, ubuntu-20.04, macos-13 ] + os: [ windows-2019, ubuntu-24.04, macos-13 ] python-version: [ 3.7, 3.8, 3.9 ] tf-version: [2.7.0, 2.8.0, 2.9.0] @@ -71,7 +71,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2019, ubuntu-20.04, macos-13 ] + os: [ windows-2019, ubuntu-24.04, macos-13 ] python-version: [ 3.7, 3.8, 3.9 ] pytorch-version: [1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0, 1.13.0] diff --git a/.github/workflows/tests_quick.yml b/.github/workflows/tests_quick.yml index b5e62c7..1a1f3c1 100644 --- a/.github/workflows/tests_quick.yml +++ b/.github/workflows/tests_quick.yml @@ -11,7 +11,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - name: Set up Python 3.6 @@ -34,7 +34,7 @@ jobs: test-tf: needs: build - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 @@ -60,7 +60,7 @@ jobs: test-torch: needs: build - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 From 181a8dd32cd0ddc341c20084fb3419ed293ae7b7 Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Tue, 28 Oct 2025 18:54:44 +0100 Subject: [PATCH 5/8] use python 3.8 min --- .github/workflows/tests_full.yml | 6 +++--- .github/workflows/tests_quick.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests_full.yml b/.github/workflows/tests_full.yml index 148adf5..278b3a4 100644 --- a/.github/workflows/tests_full.yml +++ b/.github/workflows/tests_full.yml @@ -17,10 +17,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python 3.6 + - name: Set up Python 3.8 uses: actions/setup-python@v4 with: - python-version: 3.6 + python-version: 3.8 - name: Install dependencies run: pip install wheel setuptools @@ -41,7 +41,7 @@ jobs: strategy: matrix: os: [ windows-2019, ubuntu-24.04, macos-13 ] - python-version: [ 3.7, 3.8, 3.9 ] + python-version: [ 3.7, 3.8, 3.9] tf-version: [2.7.0, 2.8.0, 2.9.0] steps: diff --git a/.github/workflows/tests_quick.yml b/.github/workflows/tests_quick.yml index 1a1f3c1..f974231 100644 --- a/.github/workflows/tests_quick.yml +++ b/.github/workflows/tests_quick.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - name: Set up Python 3.6 + - name: Set up Python 3.8 uses: actions/setup-python@v4 with: - python-version: 3.6 + python-version: 3.8 - name: Install dependencies run: pip install wheel setuptools From 3f4d9c3b46f9544c24f883e0a3bac91270c16c55 Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Tue, 28 Oct 2025 18:59:38 +0100 Subject: [PATCH 6/8] update OSes to latest --- .github/workflows/tests_full.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests_full.yml b/.github/workflows/tests_full.yml index 278b3a4..0ae12fe 100644 --- a/.github/workflows/tests_full.yml +++ b/.github/workflows/tests_full.yml @@ -40,8 +40,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2019, ubuntu-24.04, macos-13 ] - python-version: [ 3.7, 3.8, 3.9] + os: [ windows-latest, ubuntu-latest, macos-latest ] + python-version: [ 3.8, 3.9] tf-version: [2.7.0, 2.8.0, 2.9.0] steps: From 17e0a1d8031869f2e2c7c24b02cfc217cfdb23cb Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Tue, 28 Oct 2025 19:01:29 +0100 Subject: [PATCH 7/8] update OSes to latest --- .github/workflows/tests_full.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests_full.yml b/.github/workflows/tests_full.yml index 0ae12fe..e250210 100644 --- a/.github/workflows/tests_full.yml +++ b/.github/workflows/tests_full.yml @@ -71,8 +71,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-2019, ubuntu-24.04, macos-13 ] - python-version: [ 3.7, 3.8, 3.9 ] + os: [ windows-latest, ubuntu-latest, macos-latest ] + python-version: [ 3.8, 3.9 ] pytorch-version: [1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0, 1.13.0] steps: From 970f8196a076b0fd8b333c6b4cd0814ec06d18ff Mon Sep 17 00:00:00 2001 From: Carlo Alberto Barbano Date: Tue, 28 Oct 2025 19:08:25 +0100 Subject: [PATCH 8/8] use quick test --- .github/workflows/tests_full.yml | 12 ++++++------ .github/workflows/tests_quick.yml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests_full.yml b/.github/workflows/tests_full.yml index e250210..fd4dcfe 100644 --- a/.github/workflows/tests_full.yml +++ b/.github/workflows/tests_full.yml @@ -1,12 +1,12 @@ name: Full Tests on: - push: - branches: - - main - pull_request: - branches: - - main + # push: + # branches: + # - main + # pull_request: + # branches-ignore: + # - main workflow_dispatch: jobs: diff --git a/.github/workflows/tests_quick.yml b/.github/workflows/tests_quick.yml index f974231..d935ecc 100644 --- a/.github/workflows/tests_quick.yml +++ b/.github/workflows/tests_quick.yml @@ -1,13 +1,13 @@ name: Quick Tests -on: - push: - branches-ignore: - - main - pull_request: - branches-ignore: - - main - workflow_dispatch: +on: [push, pull_request, workflow_dispatch] + # push: + #branches-ignore: + # - main + # pull_request: + #branches-ignore: + # - main + # workflow_dispatch: jobs: build: