Shortcuts

mmedit.models.losses.pixelwise_loss

Module Contents

Classes

L1Loss

L1 (mean absolute error, MAE) loss.

MSELoss

MSE (L2) loss.

CharbonnierLoss

Charbonnier loss (one variant of Robust L1Loss, a differentiable variant

MaskedTVLoss

Masked TV loss.

PSNRLoss

PSNR Loss in "HINet: Half Instance Normalization Network for Image

Functions

l1_loss(→ torch.Tensor)

L1 loss.

mse_loss(→ torch.Tensor)

MSE loss.

charbonnier_loss(→ torch.Tensor)

Charbonnier loss.

tv_loss(→ torch.Tensor)

L2 total variation loss, as in Mahendran et al.

Attributes

_reduction_modes

mmedit.models.losses.pixelwise_loss._reduction_modes = ['none', 'mean', 'sum'][source]
mmedit.models.losses.pixelwise_loss.l1_loss(pred: torch.Tensor, target: torch.Tensor) torch.Tensor[source]

L1 loss.

Parameters
  • pred (Tensor) – Prediction Tensor with shape (n, c, h, w).

  • target ([type]) – Target Tensor with shape (n, c, h, w).

Returns

Calculated L1 loss.

Return type

Tensor

mmedit.models.losses.pixelwise_loss.mse_loss(pred: torch.Tensor, target: torch.Tensor) torch.Tensor[source]

MSE loss.

Parameters
  • pred (Tensor) – Prediction Tensor with shape (n, c, h, w).

  • target ([type]) – Target Tensor with shape (n, c, h, w).

Returns

Calculated MSE loss.

Return type

Tensor

mmedit.models.losses.pixelwise_loss.charbonnier_loss(pred: torch.Tensor, target: torch.Tensor, eps: float = 1e-12) torch.Tensor[source]

Charbonnier loss.

Parameters
  • pred (Tensor) – Prediction Tensor with shape (n, c, h, w).

  • target ([type]) – Target Tensor with shape (n, c, h, w).

  • eps (float) – A value used to control the curvature near zero. Default: 1e-12.

Returns

Calculated Charbonnier loss.

Return type

Tensor

mmedit.models.losses.pixelwise_loss.tv_loss(input: torch.Tensor) torch.Tensor[source]

L2 total variation loss, as in Mahendran et al.

class mmedit.models.losses.pixelwise_loss.L1Loss(loss_weight: float = 1.0, reduction: str = 'mean', sample_wise: bool = False)[source]

Bases: torch.nn.Module

L1 (mean absolute error, MAE) loss.

Parameters
  • loss_weight (float) – Loss weight for L1 loss. Default: 1.0.

  • reduction (str) – Specifies the reduction to apply to the output. Supported choices are ‘none’ | ‘mean’ | ‘sum’. Default: ‘mean’.

  • sample_wise (bool) – Whether calculate the loss sample-wise. This argument only takes effect when reduction is ‘mean’ and weight (argument of forward()) is not None. It will first reduce loss with ‘mean’ per-sample, and then it means over all the samples. Default: False.

forward(pred: torch.Tensor, target: torch.Tensor, weight: Optional[torch.Tensor] = None, **kwargs) torch.Tensor[source]

Forward Function.

Parameters
  • pred (Tensor) – of shape (N, C, H, W). Predicted tensor.

  • target (Tensor) – of shape (N, C, H, W). Ground truth tensor.

  • weight (Tensor, optional) – of shape (N, C, H, W). Element-wise weights. Default: None.

class mmedit.models.losses.pixelwise_loss.MSELoss(loss_weight: float = 1.0, reduction: str = 'mean', sample_wise: bool = False)[source]

Bases: torch.nn.Module

MSE (L2) loss.

Parameters
  • loss_weight (float) – Loss weight for MSE loss. Default: 1.0.

  • reduction (str) – Specifies the reduction to apply to the output. Supported choices are ‘none’ | ‘mean’ | ‘sum’. Default: ‘mean’.

  • sample_wise (bool) – Whether calculate the loss sample-wise. This argument only takes effect when reduction is ‘mean’ and weight (argument of forward()) is not None. It will first reduces loss with ‘mean’ per-sample, and then it means over all the samples. Default: False.

forward(pred: torch.Tensor, target: torch.Tensor, weight: Optional[torch.Tensor] = None, **kwargs) torch.Tensor[source]

Forward Function.

Parameters
  • pred (Tensor) – of shape (N, C, H, W). Predicted tensor.

  • target (Tensor) – of shape (N, C, H, W). Ground truth tensor.

  • weight (Tensor, optional) – of shape (N, C, H, W). Element-wise weights. Default: None.

class mmedit.models.losses.pixelwise_loss.CharbonnierLoss(loss_weight: float = 1.0, reduction: str = 'mean', sample_wise: bool = False, eps: float = 1e-12)[source]

Bases: torch.nn.Module

Charbonnier loss (one variant of Robust L1Loss, a differentiable variant of L1Loss).

Described in “Deep Laplacian Pyramid Networks for Fast and Accurate

Super-Resolution”.

Parameters
  • loss_weight (float) – Loss weight for L1 loss. Default: 1.0.

  • reduction (str) – Specifies the reduction to apply to the output. Supported choices are ‘none’ | ‘mean’ | ‘sum’. Default: ‘mean’.

  • sample_wise (bool) – Whether calculate the loss sample-wise. This argument only takes effect when reduction is ‘mean’ and weight (argument of forward()) is not None. It will first reduces loss with ‘mean’ per-sample, and then it means over all the samples. Default: False.

  • eps (float) – A value used to control the curvature near zero. Default: 1e-12.

forward(pred: torch.Tensor, target: torch.Tensor, weight: Optional[torch.Tensor] = None, **kwargs) torch.Tensor[source]

Forward Function.

Parameters
  • pred (Tensor) – of shape (N, C, H, W). Predicted tensor.

  • target (Tensor) – of shape (N, C, H, W). Ground truth tensor.

  • weight (Tensor, optional) – of shape (N, C, H, W). Element-wise weights. Default: None.

class mmedit.models.losses.pixelwise_loss.MaskedTVLoss(loss_weight: float = 1.0)[source]

Bases: L1Loss

Masked TV loss.

Parameters

loss_weight (float, optional) – Loss weight. Defaults to 1.0.

forward(pred: torch.Tensor, mask: Optional[torch.Tensor] = None) torch.Tensor[source]

Forward function.

Parameters
  • pred (torch.Tensor) – Tensor with shape of (n, c, h, w).

  • mask (torch.Tensor, optional) – Tensor with shape of (n, 1, h, w). Defaults to None.

Returns

[description]

Return type

[type]

class mmedit.models.losses.pixelwise_loss.PSNRLoss(loss_weight: float = 1.0, toY: bool = False)[source]

Bases: torch.nn.Module

PSNR Loss in “HINet: Half Instance Normalization Network for Image Restoration”.

Parameters
  • loss_weight (float, optional) – Loss weight. Defaults to 1.0.

  • reduction – reduction for PSNR. Can only be mean here.

  • toY – change to calculate the PSNR of Y channel in YCbCr format

forward(pred: torch.Tensor, target: torch.Tensor) torch.Tensor[source]
Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.