QNR#
- class deepinv.loss.metric.QNR(alpha: float = 1, beta: float = 1, p: float = 1, q: float = 1, **kwargs)[source]#
Bases:
Metric
Quality with No Reference (QNR) metric for pansharpening.
Calculates the no-reference QNR \(\text{QNR}(\hat{x})\) where \(\hat{x}=\inverse{y}\).
QNR was proposed in Alparone et al., “Multispectral and Panchromatic Data Fusion Assessment Without Reference”.
Note we don’t use the torchmetrics implementation.
Note
By default, no reduction is performed in the batch dimension.
- Example:
>>> import torch >>> from deepinv.loss.metric import QNR >>> from deepinv.physics import Pansharpen >>> m = QNR() >>> x = x_net = torch.rand(1, 3, 64, 64) # B,C,H,W >>> physics = Pansharpen((3, 64, 64)) >>> y = physics(x) #[BCH'W', B1HW] >>> m(x_net=x_net, y=y, physics=physics) tensor([...], grad_fn=<MulBackward0>)
- Parameters:
alpha (float) – weight for spectral quality, defaults to 1
beta (float) – weight for structural quality, defaults to 1
p (float) – power exponent for spectral D, defaults to 1
q (float) – power exponent for structural D, defaults to 1
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).train_loss (bool) – use metric as a training loss, by returning one minus the metric.
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.
- D_s(hrms: Tensor, lrms: Tensor, pan: Tensor, pan_lr: Tensor) float [source]#
Calculate spatial (or structural) distortion index.
- invert_metric(m)[source]#
Invert metric. Used where a higher=better metric is to be used in a training loss.
- Parameters:
m (Tensor) – calculated metric
- metric(x_net, x, y: TensorList, physics: Pansharpen, *args, **kwargs)[source]#
Calculate QNR on data.
Note
Note this does not require knowledge of
x
, but it is included here as a placeholder. QNR requires knowledge ofy
andphysics
, which is not standard. In order to use QNR withdeepinv.Trainer
, you will have to override thecompute_metrics
method to passy,physics
into the metric.- Parameters:
x_net (torch.Tensor) – Reconstructed high-res multispectral image \(\inverse{y}\) of shape
(B,C,H,W)
.x (torch.Tensor) – Placeholder, does nothing.
y (deepinv.utils.TensorList) – pansharpening measurements generated from
deepinv.physics.Pansharpen
, where y[0] is the low-res multispectral image of shape(B,C,H',W')
and y[1] is the high-res noisy panchromatic image of shape(B,1,H,W)
physics (deepinv.physics.Pansharpen) – pansharpening physics, used to calculate low-res pan image for QNR calculation.
- Return torch.Tensor:
calculated metric, the tensor size might be
(1,)
or(B,)
.