Spectral Angle Mapper¶
Module Interface¶
- class torchmetrics.SpectralAngleMapper(reduction='elementwise_mean', **kwargs)[source]
The Spectral Angle Mapper determines the spectral similarity between image spectra and reference spectra by calculating the angle between the spectra, where small angles between indicate high similarity and high angles indicate low similarity.
- Parameters
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'
orNone
: no reduction will be applied
kwargs¶ (
Any
) – Additional keyword arguments, see Advanced metric settings for more info.
- Returns
Tensor with SpectralAngleMapper score
Example
>>> import torch >>> from torchmetrics import SpectralAngleMapper >>> preds = torch.rand([16, 3, 16, 16], generator=torch.manual_seed(42)) >>> target = torch.rand([16, 3, 16, 16], generator=torch.manual_seed(123)) >>> sam = SpectralAngleMapper() >>> sam(preds, target) tensor(0.5943)
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.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
Functional Interface¶
- torchmetrics.functional.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 torchmetrics.functional import spectral_angle_mapper >>> preds = torch.rand([16, 3, 16, 16], generator=torch.manual_seed(42)) >>> target = torch.rand([16, 3, 16, 16], generator=torch.manual_seed(123)) >>> spectral_angle_mapper(preds, target) tensor(0.5943)
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.