MAE
- class deepinv.loss.metric.MAE(metric: Callable | None = None, complex_abs: bool = False, train_loss: bool = False, reduction: str | None = None, norm_inputs: str | None = None)[source]
Bases:
Metric
Mean Absolute Error metric.
Calculates the MAE \(\text{MAE}(\hat{x},x)\) where \(\hat{x}=\inverse{y}\).
Note
By default, no reduction is performed in the batch dimension.
Note
deepinv.metric.MAE
is functionally equivalent totorch.nn.L1Loss
whenreduction='mean'
orreduction='sum'
, but whenreduction=None
our MAE reduces over all dims except batch dim (same behaviour astorchmetrics
) whereasL1Loss
does not perform any reduction.- Example:
>>> import torch >>> from deepinv.loss.metric import MAE >>> m = MAE() >>> x_net = x = torch.ones(3, 2, 8, 8) # B,C,H,W >>> m(x_net, x) tensor([0., 0., 0.])
- Parameters:
complex_abs (bool) – perform complex magnitude before passing data to metric function. If
True
, the data must either be of complex dtype or have size 2 in the channel dimension (usually the second dimension after batch).reduction (str) – a method to reduce metric score over individual batch scores.
mean
: takes the mean,sum
takes the sum,none
or None no reduction will be applied (default).norm_inputs (str) – normalize images before passing to metric.
l2``normalizes by L2 spatial norm, ``min_max
normalizes by min and max of each input.
- metric(x_net, x, *args, **kwargs)[source]
Calculate metric on data.
Override this function to implement your own metric. Always include
args
andkwargs
arguments.- Parameters:
x_net (torch.Tensor) – Reconstructed image \(\hat{x}=\inverse{y}\) of shape
(B, ...)
or(B, C, ...)
.x (torch.Tensor) – Reference image \(x\) (optional) of shape
(B, ...)
or(B, C, ...)
.
- Return torch.Tensor:
calculated metric, the tensor size might be
(1,)
or(B,)
.