MAE#

class deepinv.loss.metric.MAE(complex_abs, reduction, norm_inputs, center_crop, ``kwargs``)[source]#

Bases: Metric

Mean Absolute Error metric.

Calculates \(\text{MAE}(\hat{x},x)\) where \(\hat{x}=\inverse{y}\).

Note

By default, no reduction is performed in the batch dimension.

Note

deepinv.loss.metric.MAE is functionally equivalent to torch.nn.L1Loss when reduction='mean' or reduction='sum', but when reduction=None our MAE reduces over all dims except batch dim (same behavior as torchmetrics) whereas L1Loss 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 \(\ell_2\) spatial norm, min_max normalizes by min and max of each input.

  • center_crop (int, tuple[int], None) – If not None (default), center crop the tensor(s) before computing the metrics. If an int is provided, the cropping is applied equally on all spatial dimensions (by default, all dimensions except the first two). If tuple of int, cropping is performed over the last len(center_crop) dimensions. If positive values are provided, a standard center crop is applied. If negative (or zero) values are passed, cropping will be done by removing center_crop pixels from the borders (useful when tensors vary in size across the dataset).