Shortcuts

pytorch_lightning.metrics.functional.regression module

pytorch_lightning.metrics.functional.regression._gaussian_kernel(channel, kernel_size, sigma, device)[source]
pytorch_lightning.metrics.functional.regression.mae(pred, target, reduction='elementwise_mean')[source]

Computes mean absolute error

Parameters
  • pred (Tensor) – estimated labels

  • target (Tensor) – ground truth labels

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass array

    • sum: add elements

Return type

Tensor

Returns

Tensor with MAE

Example

>>> x = torch.tensor([0., 1, 2, 3])
>>> y = torch.tensor([0., 1, 2, 2])
>>> mae(x, y)
tensor(0.2500)
pytorch_lightning.metrics.functional.regression.mse(pred, target, reduction='elementwise_mean')[source]

Computes mean squared error

Parameters
  • pred (Tensor) – estimated labels

  • target (Tensor) – ground truth labels

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass array

    • sum: add elements

Return type

Tensor

Returns

Tensor with MSE

Example

>>> x = torch.tensor([0., 1, 2, 3])
>>> y = torch.tensor([0., 1, 2, 2])
>>> mse(x, y)
tensor(0.2500)
pytorch_lightning.metrics.functional.regression.psnr(pred, target, data_range=None, base=10.0, reduction='elementwise_mean')[source]

Computes the peak signal-to-noise ratio

Parameters
  • pred (Tensor) – estimated signal

  • target (Tensor) – groun truth signal

  • data_range (Optional[float]) – the range of the data. If None, it is determined from the data (max - min)

  • base (float) – a base of a logarithm to use (default: 10)

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass array

    • sum add elements

Return type

Tensor

Returns

Tensor with PSNR score

Example

>>> from pytorch_lightning.metrics.regression import PSNR
>>> pred = torch.tensor([[0.0, 1.0], [2.0, 3.0]])
>>> target = torch.tensor([[3.0, 2.0], [1.0, 0.0]])
>>> metric = PSNR()
>>> metric(pred, target)
tensor(2.5527)
pytorch_lightning.metrics.functional.regression.rmse(pred, target, reduction='elementwise_mean')[source]

Computes root mean squared error

Parameters
  • pred (Tensor) – estimated labels

  • target (Tensor) – ground truth labels

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass array

    • sum: add elements

Return type

Tensor

Returns

Tensor with RMSE

>>> x = torch.tensor([0., 1, 2, 3])
>>> y = torch.tensor([0., 1, 2, 2])
>>> rmse(x, y)
tensor(0.5000)

pytorch_lightning.metrics.functional.regression.rmsle(pred, target, reduction='elementwise_mean')[source]

Computes root mean squared log error

Parameters
  • pred (Tensor) – estimated labels

  • target (Tensor) – ground truth labels

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass array

    • sum: add elements

Return type

Tensor

Returns

Tensor with RMSLE

Example

>>> x = torch.tensor([0., 1, 2, 3])
>>> y = torch.tensor([0., 1, 2, 2])
>>> rmsle(x, y)
tensor(0.0207)
pytorch_lightning.metrics.functional.regression.ssim(pred, target, kernel_size=(11, 11), sigma=(1.5, 1.5), reduction='elementwise_mean', data_range=None, k1=0.01, k2=0.03)[source]

Computes Structual Similarity Index Measure

Parameters
  • pred (Tensor) – estimated image

  • target (Tensor) – ground truth image

  • kernel_size (Sequence[int]) – size of the gaussian kernel (default: (11, 11))

  • sigma (Sequence[float]) – Standard deviation of the gaussian kernel (default: (1.5, 1.5))

  • reduction (str) –

    a method to reduce metric score over labels (default: takes the mean) Available reduction methods:

    • elementwise_mean: takes the mean

    • none: pass away

    • sum: add elements

  • data_range (Optional[float]) – Range of the image. If None, it is determined from the image (max - min)

  • k1 (float) – Parameter of SSIM. Default: 0.01

  • k2 (float) – Parameter of SSIM. Default: 0.03

Return type

Tensor

Returns

Tensor with SSIM score

Example

>>> pred = torch.rand([16, 1, 16, 16])
>>> target = pred * 0.75
>>> ssim(pred, target)
tensor(0.9219)