GMSD#

class deepinv.loss.metric.GMSD(c=0.0026, **kwargs)[source]#

Bases: Metric

Gradient Magnitude Similarity Deviation (GMSD) metric.

Calculates \(\text{GMSD}(\hat{x},x)\), as proposed in Xue et al.[1]. GMSD measures perceptual image quality from the standard deviation of the pixel-wise gradient magnitude similarity (GMS) map. A lower value indicates better quality.

The reference and reconstructed gradient magnitudes \(m_x\) and \(m_{\hat{x}}\) are computed using the Prewitt operators \(h_x, h_y\),

\[m_x = \sqrt{(x \ast h_x)^2 + (x \ast h_y)^2},\qquad m_{\hat{x}} = \sqrt{(\hat{x} \ast h_x)^2 + (\hat{x} \ast h_y)^2},\]

where \(\ast\) denotes 2D convolution. The pixel-wise GMS map is

\[\text{GMS}(\hat{x},x) = \frac{2 m_x m_{\hat{x}} + c}{m_x^2 + m_{\hat{x}}^2 + c},\]

where c is a small stability constant. GMSD is the spatial standard deviation of this map computed independently for each image in the batch. For multi-channel images, GMSD is calculated independently for each channel, then averaged across channels to produce a single scalar per image.

Example:

>>> import torch
>>> from deepinv.loss.metric import GMSD
>>> m = GMSD()
>>> x_net = x = torch.ones(3, 1, 8, 8) # B,1,H,W
>>> m(x_net, x)
tensor([0., 0., 0.])
Parameters:
  • c (float) – positive stability constant \(c\) of the GMS map. The original paper uses \(c=170\) for images in \([0, 255]\). Rescale accordingly for images in \([0, 1]\). Default: 0.0026.

  • 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).


References: