qualitywithnoreference
Metric
QualityWithNoReferencefromtorchmetrics(torchmetrics.image.QualityWithNoReference)
When to invoke this skill
The user has predictions + ground truth and asks to evaluate with QualityWithNoReference, or
mentions torchmetrics.image.QualityWithNoReference directly, or wants the standard torchmetrics implementation.
Reference signature
from torchmetrics.image import QualityWithNoReference
# QualityWithNoReference(alpha: float = 1, beta: float = 1, norm_order: int = 1, window_size: int = 7, reduction: Literal['elementwise_mean', 'sum', 'none'] = 'elementwise_mean', **kwargs: Any) -> None
Library docstring
Compute Quality with No Reference (QualityWithNoReference_) also now as QNR.
The metric is used to compare the joint spectral and spatial distortion between two images.
As input to ``forward`` and ``update`` the metric accepts the following input
- ``preds`` (:class:`~torch.Tensor`): High resolution multispectral image of shape ``(N,C,H,W)``.
- ``target`` (:class:`~Dict`): A dictionary containing the following keys:
- ``ms`` (:class:`~torch.Tensor`): Low resolution multispectral image of shape ``(N,C,H',W')``.
- ``pan`` (:class:`~torch.Tensor`): High resolution panchromatic image of shape ``(N,C,H,W)``.
- ``pan_lr`` (:class:`~torch.Tensor`): (optional) Low resolution panchromatic image of shape ``(N,C,H',W')``.
where H and W must be multiple of H' and W'.
When ``pan_lr`` is ``None``, a uniform filter will be applied on ``pan`` to produce a degraded image. The degraded
image is then resized to match the size of ``ms`` and served as ``pan_lr`` in the calculation.
As output of `forward` and `compute` the metric returns the following output
- ``qnr`` (:class:`~torch.Tensor`): if ``reduction!='none'`` returns float scalar tensor with average QNR value
over sample else returns tensor of shape ``(N,)`` with QNR values per sample
Args:
alpha: Relevance of spectral distortion.
beta: Relevance of spatial distortion.
norm_order: Order of the norm applied on the difference.
window_size: Window size of the filter applied to degrade the high resolution panchromatic image.
reduction: a method to reduce metric score over labels.
- ``'elementwise_mean'``: takes the mean (default)
- ``'sum'``: takes the sum
- ``'none'``: no reduction will be applied
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
Example:
>>> from torch import rand
>>> from torchmetrics.image import QualityWithNoReference
>>> preds = rand([16, 3, 32, 32])
>>> target = {
... 'ms': rand([16, 3, 16, 16]),
... 'pan': rand([16, 3, 32, 32]),
... }
>>> qnr = QualityWithNoReference()
>>> qnr(preds, target)
tensor(0.9694)
Quick recipe
import torchmetrics.image as _m
score = _m.QualityWithNoReference(y_true, y_pred)
Don'ts
- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is
(y_true, y_pred)while torchmetrics is(preds, target).