SpectralAngleMapper#
- class deepinv.loss.metric.SpectralAngleMapper(metric=None, complex_abs=False, train_loss=False, reduction=None, norm_inputs=None, center_crop=None)[source]#
Bases:
MetricSpectral Angle Mapper (SAM).
Calculates spectral similarity between estimated and target multispectral images.
Wraps the
torchmetricsSpectral Angle Mapper function. Note that ourreductionparameter follows our uniform convention (see below).Note
By default, no reduction is performed in the batch dimension.
- Example:
>>> import torch >>> from deepinv.loss.metric import SpectralAngleMapper >>> m = SpectralAngleMapper() >>> x_net = x = torch.ones(3, 2, 8, 8) # B,C,H,W >>> m(x_net, x) tensor([0., 0., 0.])
- Parameters:
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,sumtakes the sum,noneor None no reduction will be applied (default).norm_inputs (str) – normalize images before passing to metric.
l2normalizes by \(\ell_2\) spatial norm,min_maxnormalizes by min and max of each input.center_crop (int, tuple[int], None) – If not
None(default), center crop the tensor(s) before computing the metrics. If anintis provided, the cropping is applied equally on all spatial dimensions (by default, all dimensions except the first two). Iftupleofint, cropping is performed over the lastlen(center_crop)dimensions. If positive values are provided, a standard center crop is applied. If negative (or zero) values are passed, cropping will be done by removingcenter_croppixels from the borders (useful when tensors vary in size across the dataset).