Skip to content
Open
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 monai/metrics/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _cov(input_data: torch.Tensor, rowvar: bool = True) -> torch.Tensor:

def _sqrtm(input_data: torch.Tensor) -> torch.Tensor:
"""Compute the square root of a matrix."""
scipy_res, _ = scipy.linalg.sqrtm(input_data.detach().cpu().numpy().astype(np.float64), disp=False)
scipy_res = scipy.linalg.sqrtm(input_data.detach().cpu().numpy().astype(np.float64))
return torch.from_numpy(scipy_res)


Expand Down
7 changes: 7 additions & 0 deletions tests/metrics/test_compute_fid_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import torch

from monai.metrics import FIDMetric
from monai.metrics.fid import _sqrtm
from monai.utils import optional_import

_, has_scipy = optional_import("scipy")
Expand All @@ -25,6 +26,12 @@
@unittest.skipUnless(has_scipy, "Requires scipy")
class TestFIDMetric(unittest.TestCase):

def test_sqrtm_returns_tensor(self):
"""``scipy.linalg.sqrtm`` dropped its ``disp`` argument, and with it the 2-tuple return."""
result = _sqrtm(torch.tensor([[4.0, 0.0], [0.0, 9.0]], dtype=torch.float64))
self.assertIsInstance(result, torch.Tensor)
np.testing.assert_allclose(result.cpu().numpy(), np.array([[2.0, 0.0], [0.0, 3.0]]), atol=1e-6)

def test_results(self):
x = torch.Tensor([[1, 2], [1, 2], [1, 2]])
y = torch.Tensor([[2, 2], [1, 2], [1, 2]])
Expand Down
Loading