Quality with No Reference¶
Module Interface¶
- class torchmetrics.image.QualityWithNoReference(alpha=1, beta=1, norm_order=1, window_size=7, reduction='elementwise_mean', **kwargs)[source]¶
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
andupdate
the metric accepts the following inputpreds
(Tensor
): High resolution multispectral image of shape(N,C,H,W)
.target
(Dict
): A dictionary containing the following keys:
where H and W must be multiple of H’ and W’.
When
pan_lr
isNone
, a uniform filter will be applied onpan
to produce a degraded image. The degraded image is then resized to match the size ofms
and served aspan_lr
in the calculation.As output of forward and compute the metric returns the following output
qnr
(Tensor
): ifreduction!='none'
returns float scalar tensor with average QNR value over sample else returns tensor of shape(N,)
with QNR values per sample
- Parameters:
norm_order¶ (
int
) – Order of the norm applied on the difference.window_size¶ (
int
) – Window size of the filter applied to degrade the high resolution panchromatic image.reduction¶ (
Literal
['elementwise_mean'
,'sum'
,'none'
]) –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¶ (
Any
) – Additional keyword arguments, see Advanced metric settings 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)
- plot(val=None, ax=None)[source]¶
Plot a single or multiple values from the metric.
- Parameters:
val¶ (
Union
[Tensor
,Sequence
[Tensor
],None
]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.ax¶ (
Optional
[Axes
]) – An matplotlib axis object. If provided will add plot to that axis
- Return type:
- Returns:
Figure and Axes object
- Raises:
ModuleNotFoundError – If matplotlib is not installed
>>> # Example plotting a single value >>> 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]), ... } >>> metric = QualityWithNoReference() >>> metric.update(preds, target) >>> fig_, ax_ = metric.plot()
>>> # Example plotting multiple values >>> 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]), ... } >>> metric = QualityWithNoReference() >>> values = [ ] >>> for _ in range(10): ... values.append(metric(preds, target)) >>> fig_, ax_ = metric.plot(values)
Functional Interface¶
- torchmetrics.functional.image.quality_with_no_reference(preds, ms, pan, pan_lr=None, alpha=1, beta=1, norm_order=1, window_size=7, reduction='elementwise_mean')[source]¶
Calculate Quality with No Reference (QualityWithNoReference) also known as QNR.
Metric is used to compare the joint spectral and spatial distortion between two images.
- Parameters:
pan_lr¶ (
Optional
[Tensor
]) – Low resolution panchromatic image.norm_order¶ (
int
) – Order of the norm applied on the difference.window_size¶ (
int
) – Window size of the filter applied to degrade the high resolution panchromatic image.reduction¶ (
Literal
['elementwise_mean'
,'sum'
,'none'
]) –A method to reduce metric score over labels.
'elementwise_mean'
: takes the mean (default)'sum'
: takes the sum'none'
: no reduction will be applied
- Return type:
- Returns:
Tensor with QualityWithNoReference score
- Raises:
ValueError – If
alpha
orbeta
is not a non-negative real number.
Example
>>> from torch import rand >>> from torchmetrics.functional.image import quality_with_no_reference >>> preds = rand([16, 3, 32, 32]) >>> ms = rand([16, 3, 16, 16]) >>> pan = rand([16, 3, 32, 32]) >>> quality_with_no_reference(preds, ms, pan) tensor(0.9694)