piqa.psnr#
Peak Signal-to-Noise Ratio (PSNR)
This module implements the PSNR in PyTorch.
Wikipedia
https://wikipedia.org/wiki/Peak_signal-to-noise_ratio
Functions#
Classes#
Measures the PSNR between an input and a target. |
Descriptions#
- piqa.psnr.mse(x, y)#
Returns the Mean Squared Error (MSE) between \(x\) and \(y\).
\[\text{MSE}(x, y) = \frac{1}{\text{size}(x)} \sum_i (x_i - y_i)^2\]- Parameters:
- Returns:
The MSE vector, \((N,)\).
- Return type:
Example
>>> x = torch.rand(5, 3, 256, 256) >>> y = torch.rand(5, 3, 256, 256) >>> l = mse(x, y) >>> l.shape torch.Size([5])
- piqa.psnr.psnr(x, y, epsilon=1e-08, value_range=1.0)#
Returns the PSNR between \(x\) and \(y\).
\[\text{PSNR}(x, y) = 10 \log_{10} \left( \frac{L^2}{\text{MSE}(x, y)} \right)\]- Parameters:
- Returns:
The PSNR vector, \((N,)\).
- Return type:
Example
>>> x = torch.rand(5, 3, 256, 256) >>> y = torch.rand(5, 3, 256, 256) >>> l = psnr(x, y) >>> l.shape torch.Size([5])
- class piqa.psnr.PSNR(reduction='mean', **kwargs)#
Measures the PSNR between an input and a target.
- Parameters:
Example
>>> criterion = PSNR() >>> x = torch.rand(5, 3, 256, 256, requires_grad=True) >>> y = torch.rand(5, 3, 256, 256) >>> l = -criterion(x, y) >>> l.shape torch.Size([]) >>> l.backward()