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
2 changes: 1 addition & 1 deletion .github/workflows/tests_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
matrix:
os: [ windows-2019, ubuntu-18.04, macos-11 ]
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
pytorch-version: [1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0]
pytorch-version: [1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0, 1.13.0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just handling new/older torch version in the repo that remains :]

exclude:
- python-version: 3.6
pytorch-version: 1.11.0
Expand Down
1 change: 0 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
t_ = time.time()
norm, H, E = tf_normalizer.normalize(I=t_to_transform, stains=True)
print("tf runtime:", time.time() - t_)

plt.figure()
plt.suptitle('tensorflow normalizer')
plt.subplot(2, 2, 1)
Expand Down
10 changes: 7 additions & 3 deletions torchstain/torch/normalizers/macenko.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def __init__(self):
[0.7201, 0.8012],
[0.4062, 0.5581]])
self.maxCRef = torch.tensor([1.9705, 1.0308])

self.deprecated_torch = torch.__version__ < (1,9,0)

def __convert_rgb2od(self, I, Io, beta):
I = I.permute(1, 2, 0)

Expand Down Expand Up @@ -49,13 +50,16 @@ def __find_concentration(self, OD, HE):
Y = OD.T

# determine concentrations of the individual stains
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I am not sure that doing this is backward compatible, as I believe torch.linalg.lstsq does not exist in older versions of torch. You will need to find a fix that works for all versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the Torch repo that change was made in Torch 1.9. I suggest bumping the minimum version of Torch required from 1.8 to 1.9 to assure backward compatibility:

https://github.com/pytorch/pytorch/blob/b0c86caa1d46a16195682e2afe5456f97265aa53/torch/_linalg_utils.py#L111

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are surprisingly many people that use older versions of pytorch and tf. Also, 1.9 isn't really that old.

I think a good fix for this is to check which pytorch version that is used and introduce a if statement to handle older versions. You can get the torch version by:

import torch
print(torch.__version__)

return torch.lstsq(Y, HE)[0][:2]
if self.deprecated_torch:
return torch.lstsq(Y, HE)[0][:2]

return torch.linalg.lstsq(HE, Y)[0]

def __compute_matrices(self, I, Io, alpha, beta):
OD, ODhat = self.__convert_rgb2od(I, Io=Io, beta=beta)

# compute eigenvectors
_, eigvecs = torch.symeig(cov(ODhat.T), eigenvectors=True)
_, eigvecs = torch.linalg.eigh(cov(ODhat.T))
eigvecs = eigvecs[:, [1, 2]]

HE = self.__find_HE(ODhat, eigvecs, alpha)
Expand Down