Scale-Invariant Signal-to-Noise Ratio (SI-SNR)¶
Module Interface¶
- class torchmetrics.audio.ScaleInvariantSignalNoiseRatio(**kwargs)[source]¶
Calculate Scale-invariant signal-to-noise ratio (SI-SNR) metric for evaluating quality of audio.
As input to forward and update the metric accepts the following input
preds
(Tensor
): float tensor with shape(...,time)
target
(Tensor
): float tensor with shape(...,time)
As output of forward and compute the metric returns the following output
si_snr
(Tensor
): float scalar tensor with average SI-SNR value over samples
- Parameters:
kwargs¶ (
Any
) – Additional keyword arguments, see Advanced metric settings for more info.- Raises:
TypeError – if target and preds have a different shape
Example
>>> import torch >>> from torch import tensor >>> from torchmetrics.audio import ScaleInvariantSignalNoiseRatio >>> target = tensor([3.0, -0.5, 2.0, 7.0]) >>> preds = tensor([2.5, 0.0, 2.0, 8.0]) >>> si_snr = ScaleInvariantSignalNoiseRatio() >>> si_snr(preds, target) tensor(15.0918)
- plot(val=None, ax=None)[source]¶
Plot a single or multiple values from the metric.
- Parameters:
val¶ (
Union
[Tensor
,Sequence
[Tensor
],None
]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.ax¶ (
Optional
[Axes
]) – An matplotlib axis object. If provided will add plot to that axis
- Return type:
- Returns:
Figure and Axes object
- Raises:
ModuleNotFoundError – If matplotlib is not installed
>>> # Example plotting a single value >>> import torch >>> from torchmetrics.audio import ScaleInvariantSignalNoiseRatio >>> metric = ScaleInvariantSignalNoiseRatio() >>> metric.update(torch.rand(4), torch.rand(4)) >>> fig_, ax_ = metric.plot()
>>> # Example plotting multiple values >>> import torch >>> from torchmetrics.audio import ScaleInvariantSignalNoiseRatio >>> metric = ScaleInvariantSignalNoiseRatio() >>> values = [ ] >>> for _ in range(10): ... values.append(metric(torch.rand(4), torch.rand(4))) >>> fig_, ax_ = metric.plot(values)
Functional Interface¶
- torchmetrics.functional.audio.scale_invariant_signal_noise_ratio(preds, target)[source]¶
Scale-invariant signal-to-noise ratio (SI-SNR).
- Parameters:
- Return type:
- Returns:
Float tensor with shape
(...,)
of SI-SNR values per sample- Raises:
RuntimeError – If
preds
andtarget
does not have the same shape
Example
>>> import torch >>> from torchmetrics.functional.audio import scale_invariant_signal_noise_ratio >>> target = torch.tensor([3.0, -0.5, 2.0, 7.0]) >>> preds = torch.tensor([2.5, 0.0, 2.0, 8.0]) >>> scale_invariant_signal_noise_ratio(preds, target) tensor(15.0918)