Shortcuts

pytorch_lightning.metrics.regression module

class pytorch_lightning.metrics.regression.MAE(reduction='elementwise_mean')[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes the mean absolute loss or L1-loss.

Example

>>> pred = torch.tensor([0., 1, 2, 3])
>>> target = torch.tensor([0., 1, 2, 2])
>>> metric = MAE()
>>> metric(pred, target)
tensor(0.2500)
Parameters

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

forward(pred, target)[source]

Actual metric computation

Parameters
  • pred (Tensor) – predicted labels

  • target (Tensor) – ground truth labels

Return type

Tensor

Returns

A Tensor with the mae loss.

class pytorch_lightning.metrics.regression.MSE(reduction='elementwise_mean')[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes the mean squared loss.

Example

>>> pred = torch.tensor([0., 1, 2, 3])
>>> target = torch.tensor([0., 1, 2, 2])
>>> metric = MSE()
>>> metric(pred, target)
tensor(0.2500)
Parameters

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

forward(pred, target)[source]

Actual metric computation

Parameters
  • pred (Tensor) – predicted labels

  • target (Tensor) – ground truth labels

Return type

Tensor

Returns

A Tensor with the mse loss.

class pytorch_lightning.metrics.regression.PSNR(data_range=None, base=10, reduction='elementwise_mean')[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes the peak signal-to-noise ratio

Example

>>> 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)
Parameters
  • data_range (Optional[float]) – the range of the data. If None, it is determined from the data (max - min)

  • base (int) – 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

forward(pred, target)[source]

Actual metric computation

Parameters
  • pred (Tensor) – predicted labels

  • target (Tensor) – ground truth labels

Return type

Tensor

Returns

A Tensor with psnr score.

class pytorch_lightning.metrics.regression.RMSE(reduction='elementwise_mean')[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes the root mean squared loss.

Example

>>> pred = torch.tensor([0., 1, 2, 3])
>>> target = torch.tensor([0., 1, 2, 2])
>>> metric = RMSE()
>>> metric(pred, target)
tensor(0.5000)
Parameters

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

forward(pred, target)[source]

Actual metric computation

Parameters
  • pred (Tensor) – predicted labels

  • target (Tensor) – ground truth labels

Return type

Tensor

Returns

A Tensor with the rmse loss.

class pytorch_lightning.metrics.regression.RMSLE(reduction='elementwise_mean')[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes the root mean squared log loss.

Example

>>> pred = torch.tensor([0., 1, 2, 3])
>>> target = torch.tensor([0., 1, 2, 2])
>>> metric = RMSLE()
>>> metric(pred, target)
tensor(0.0207)
Parameters

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

forward(pred, target)[source]

Actual metric computation

Parameters
  • pred (Tensor) – predicted labels

  • target (Tensor) – ground truth labels

Return type

Tensor

Returns

A Tensor with the rmsle loss.

class pytorch_lightning.metrics.regression.SSIM(kernel_size=(11, 11), sigma=(1.5, 1.5), reduction='elementwise_mean', data_range=None, k1=0.01, k2=0.03)[source]

Bases: pytorch_lightning.metrics.metric.Metric

Computes Structual Similarity Index Measure

Example

>>> pred = torch.rand([16, 1, 16, 16])
>>> target = pred * 0.75
>>> metric = SSIM()
>>> metric(pred, target)
tensor(0.9219)
Parameters
  • 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

forward(pred, target)[source]

Actual metric computation

Parameters
Return type

Tensor

Returns

A Tensor with SSIM score.