Spectral Angle Mapper¶
Module Interface¶
- class torchmetrics.image.SpectralAngleMapper(reduction='elementwise_mean', **kwargs)[source]¶
Spectral Angle Mapper determines the spectral similarity between image spectra and reference spectra.
It works by calculating the angle between the spectra, where small angles between indicate high similarity and high angles indicate low similarity.
As input to
forward
andupdate
the metric accepts the following inputpreds
(Tensor
): Predictions from model of shape(N,C,H,W)
target
(Tensor
): Ground truth values of shape(N,C,H,W)
As output of forward and compute the metric returns the following output
sam
(Tensor
): ifreduction!='none'
returns float scalar tensor with average SAM value over sample else returns tensor of shape(N,)
with SAM values per sample
- Parameters:
reduction¶ (
Optional
[Literal
['elementwise_mean'
,'sum'
,'none'
]]) –a method to reduce metric score over labels.
'elementwise_mean'
: takes the mean (default)'sum'
: takes the sum'none'
orNone
: no reduction will be applied
kwargs¶ (
Any
) – Additional keyword arguments, see Advanced metric settings for more info.
- Returns:
Tensor with SpectralAngleMapper score
Example
>>> from torch import rand >>> from torchmetrics.image import SpectralAngleMapper >>> preds = rand([16, 3, 16, 16]) >>> target = rand([16, 3, 16, 16]) >>> sam = SpectralAngleMapper() >>> sam(preds, target) tensor(0.5914)
- 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 single value >>> from torch import rand >>> from torchmetrics.image import SpectralAngleMapper >>> preds = rand([16, 3, 16, 16]) >>> target = rand([16, 3, 16, 16]) >>> metric = SpectralAngleMapper() >>> metric.update(preds, target) >>> fig_, ax_ = metric.plot()
>>> # Example plotting multiple values >>> from torch import rand >>> from torchmetrics.image import SpectralAngleMapper >>> preds = rand([16, 3, 16, 16]) >>> target = rand([16, 3, 16, 16]) >>> metric = SpectralAngleMapper() >>> values = [ ] >>> for _ in range(10): ... values.append(metric(preds, target)) >>> fig_, ax_ = metric.plot(values)
Functional Interface¶
- torchmetrics.functional.image.spectral_angle_mapper(preds, target, reduction='elementwise_mean')[source]¶
Universal Spectral Angle Mapper.
- Parameters:
- Return type:
- Returns:
Tensor with Spectral Angle Mapper score
- Raises:
TypeError – If
preds
andtarget
don’t have the same data type.ValueError – If
preds
andtarget
don’t haveBxCxHxW shape
.
Example
>>> from torch import rand >>> from torchmetrics.functional.image import spectral_angle_mapper >>> preds = rand([16, 3, 16, 16],) >>> target = rand([16, 3, 16, 16]) >>> spectral_angle_mapper(preds, target) tensor(0.5914)
References
[1] Roberta H. Yuhas, Alexander F. H. Goetz and Joe W. Boardman, “Discrimination among semi-arid landscape endmembers using the Spectral Angle Mapper (SAM) algorithm” in PL, Summaries of the Third Annual JPL Airborne Geoscience Workshop, vol. 1, June 1, 1992.