Shortcuts

Complex Scale-Invariant Signal-to-Noise Ratio (C-SI-SNR)

Module Interface

class torchmetrics.audio.ComplexScaleInvariantSignalNoiseRatio(zero_mean=False, **kwargs)[source]

Calculate Complex scale-invariant signal-to-noise ratio (C-SI-SNR) metric for evaluating quality of audio.

As input to forward and update the metric accepts the following input

  • preds (Tensor): real float tensor with shape (...,frequency,time,2) or complex float tensor with shape (..., frequency,time)

  • target (Tensor): real float tensor with shape (...,frequency,time,2) or complex float tensor with shape (..., frequency,time)

As output of forward and compute the metric returns the following output

  • c_si_snr (Tensor): float scalar tensor with average C-SI-SNR value over samples

Parameters:
Raises:
  • ValueError – If zero_mean is not an bool

  • TypeError – If preds is not the shape (…, frequency, time, 2) (after being converted to real if it is complex). If preds and target does not have the same shape.

Example

>>> import torch
>>> from torch import tensor
>>> from torchmetrics.audio import ComplexScaleInvariantSignalNoiseRatio
>>> g = torch.manual_seed(1)
>>> preds = torch.randn((1,257,100,2))
>>> target = torch.randn((1,257,100,2))
>>> c_si_snr = ComplexScaleInvariantSignalNoiseRatio()
>>> c_si_snr(preds, target)
tensor(-63.4849)
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:

Tuple[Figure, Union[Axes, ndarray]]

Returns:

Figure and Axes object

Raises:

ModuleNotFoundError – If matplotlib is not installed

>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.audio import ComplexScaleInvariantSignalNoiseRatio
>>> metric = ComplexScaleInvariantSignalNoiseRatio()
>>> metric.update(torch.rand(1,257,100,2), torch.rand(1,257,100,2))
>>> fig_, ax_ = metric.plot()
../_images/complex_scale_invariant_signal_noise_ratio-1.png
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.audio import ComplexScaleInvariantSignalNoiseRatio
>>> metric = ComplexScaleInvariantSignalNoiseRatio()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(torch.rand(1,257,100,2), torch.rand(1,257,100,2)))
>>> fig_, ax_ = metric.plot(values)
../_images/complex_scale_invariant_signal_noise_ratio-2.png

Functional Interface

torchmetrics.functional.audio.complex_scale_invariant_signal_noise_ratio(preds, target, zero_mean=False)[source]

Complex scale-invariant signal-to-noise ratio (C-SI-SNR).

Parameters:
  • preds (Tensor) – real float tensor with shape (...,frequency,time,2) or complex float tensor with shape (..., frequency,time)

  • target (Tensor) – real float tensor with shape (...,frequency,time,2) or complex float tensor with shape (..., frequency,time)

  • zero_mean (bool) – When set to True, the mean of all signals is subtracted prior to computation of the metrics

Return type:

Tensor

Returns:

Float tensor with shape (...,) of C-SI-SNR values per sample

Raises:

RuntimeError – If preds is not the shape (…,frequency,time,2) (after being converted to real if it is complex). If preds and target does not have the same shape.

Example

>>> import torch
>>> from torchmetrics.functional.audio import complex_scale_invariant_signal_noise_ratio
>>> g = torch.manual_seed(1)
>>> preds = torch.randn((1,257,100,2))
>>> target = torch.randn((1,257,100,2))
>>> complex_scale_invariant_signal_noise_ratio(preds, target)
tensor([-63.4849])
Read the Docs v: stable
Versions
latest
stable
v1.1.0
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v0.11.4
v0.11.3
v0.11.2
v0.11.1
v0.11.0
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
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
Downloads
pdf
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.