Shortcuts

Peak Signal-to-Noise Ratio (PSNR)¶

Module Interface¶

class torchmetrics.PeakSignalNoiseRatio(data_range=None, base=10.0, reduction='elementwise_mean', dim=None, compute_on_step=None, **kwargs)[source]

Computes Computes Peak Signal-to-Noise Ratio (PSNR):

Where denotes the mean-squared-error function.

Parameters
Raises

ValueError – If dim is not None and data_range is not given.

Example

>>> from torchmetrics import PeakSignalNoiseRatio
>>> psnr = PeakSignalNoiseRatio()
>>> preds = torch.tensor([[0.0, 1.0], [2.0, 3.0]])
>>> target = torch.tensor([[3.0, 2.0], [1.0, 0.0]])
>>> psnr(preds, target)
tensor(2.5527)


Note

Half precision is only support on GPU for this metric

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Compute peak signal-to-noise ratio over state.

Return type

Tensor

update(preds, target)[source]

Update state with predictions and targets.

Parameters
Return type

None

Functional Interface¶

torchmetrics.functional.peak_signal_noise_ratio(preds, target, data_range=None, base=10.0, reduction='elementwise_mean', dim=None)[source]

Computes the peak signal-to-noise ratio.

Parameters
Return type

Tensor

Returns

Tensor with PSNR score

Raises

ValueError – If dim is not None and data_range is not provided.

Example

>>> from torchmetrics.functional import peak_signal_noise_ratio
>>> pred = torch.tensor([[0.0, 1.0], [2.0, 3.0]])
>>> target = torch.tensor([[3.0, 2.0], [1.0, 0.0]])
>>> peak_signal_noise_ratio(pred, target)
tensor(2.5527)


Note

Half precision is only support on GPU for this metric

© Copyright Copyright (c) 2020-2022, PyTorchLightning et al... Revision 60f1f185.

Built with Sphinx using a theme provided by Read the Docs.
Versions
latest
stable
v0.8.2
v0.8.1
v0.8.0
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.2
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.1
v0.4.0
v0.3.2
v0.3.1
v0.3.0
v0.2.0
v0.1.0