mmagic.models.losses.pixelwise_loss
¶
Module Contents¶
Classes¶
L1 (mean absolute error, MAE) loss. |
|
MSE (L2) loss. |
|
Charbonnier loss (one variant of Robust L1Loss, a differentiable variant |
|
Masked TV loss. |
|
PSNR Loss in "HINet: Half Instance Normalization Network for Image |
Functions¶
|
L1 loss. |
|
MSE loss. |
|
Charbonnier loss. |
|
L2 total variation loss, as in Mahendran et al. |
Attributes¶
- mmagic.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
- mmagic.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
- mmagic.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
- mmagic.models.losses.pixelwise_loss.tv_loss(input: torch.Tensor) torch.Tensor [source]¶
L2 total variation loss, as in Mahendran et al.
- class mmagic.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 mmagic.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 mmagic.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 mmagic.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.
- class mmagic.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