Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

signal->input, approximation->target

ananyamukh6eb7677c5736e
diff --git a/kornia/losses/psnr.py b/kornia/losses/psnr.py
index f57d8098c..2b7588206 100644
--- a/kornia/losses/psnr.py
+++ b/kornia/losses/psnr.py
@@ -7,11 +7,11 @@ class PSNRLoss(nn.Module):
r"""Creates a criterion that calculates the PSNR between 2 images.
Arguments:
- max_val (float): Maximum value of signal
+ max_val (float): Maximum value of input
Shape:
- - signal: :math:`(*)`
- - approximation: :math:`(*)` same shape as signal
+ - input: :math:`(*)`
+ - approximation: :math:`(*)` same shape as input
- output: :math:`()` a scalar
Examples:
@@ -27,18 +27,18 @@ class PSNRLoss(nn.Module):
self.max_val = max_val
def forward( # type: ignore
- self, signal: torch.Tensor, approximation: torch.Tensor) -> torch.Tensor:
- return psnr_loss(signal, approximation, self.max_val)
+ self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
+ return psnr_loss(input, target, self.max_val)
-def psnr_loss(signal: torch.Tensor, approximation: torch.Tensor, max_val) -> torch.Tensor:
+def psnr_loss(input: torch.Tensor, target: torch.Tensor, max_val) -> torch.Tensor:
r"""Function that computes PSNR
See :class:`~kornia.losses.PSNR` for details.
"""
- if not torch.is_tensor(signal) or not torch.is_tensor(approximation):
- raise TypeError(f"Expected 2 torch tensors but got {type(signal)} and {type(approximation)}")
- if signal.shape != approximation.shape:
- raise TypeError(f"Expected tensors of equal shapes, but got {signal.shape} and {approximation.shape}")
- mse_val = mse_loss(signal, approximation, reduction='mean')
+ if not torch.is_tensor(input) or not torch.is_tensor(target):
+ raise TypeError(f"Expected 2 torch tensors but got {type(input)} and {type(target)}")
+ if input.shape != target.shape:
+ raise TypeError(f"Expected tensors of equal shapes, but got {input.shape} and {target.shape}")
+ mse_val = mse_loss(input, target, reduction='mean')
return 10 * torch.log10(max_val * max_val / mse_val)
diff --git a/test/test_losses.py b/test/test_losses.py
index 8bd739bef..40594a3a8 100644
--- a/test/test_losses.py
+++ b/test/test_losses.py
@@ -344,20 +344,20 @@ class TestTotalVariation:
class TestPSNRLoss:
def test_smoke(self):
- signal = torch.rand(2, 3, 3, 2)
- approximation = torch.rand(2, 3, 3, 2)
+ input = torch.rand(2, 3, 3, 2)
+ target = torch.rand(2, 3, 3, 2)
criterion = kornia.losses.PSNRLoss(1.0)
- loss = criterion(signal, approximation)
+ loss = criterion(input, target)
assert loss.shape == tuple()
- def test_same_signal(self):
- signal = torch.rand(2, 3, 3, 2)
- approximation = signal
+ def test_same_input(self):
+ input = torch.rand(2, 3, 3, 2)
+ target = input
criterion = kornia.losses.PSNRLoss(1.0)
- loss = criterion(signal, approximation)
+ loss = criterion(input, target)
assert_allclose(loss, torch.tensor(float('inf')))
@@ -383,10 +383,10 @@ class TestPSNRLoss:
pass
def test_gradcheck(self):
- signal = torch.rand(2, 3, 3, 2).double()
- approximation = torch.rand(2, 3, 3, 2).double()
+ input = torch.rand(2, 3, 3, 2).double()
+ target = torch.rand(2, 3, 3, 2).double()
- signal = utils.tensor_to_gradcheck_var(signal) # to var
+ input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(
- kornia.losses.psnr_loss, (signal, approximation, 1.0), raise_exception=True
+ kornia.losses.psnr_loss, (input, target, 1.0), raise_exception=True
)