structuralsimilarityindexmeasure
Metric
StructuralSimilarityIndexMeasurefromtorchmetrics(torchmetrics.StructuralSimilarityIndexMeasure)
When to invoke this skill
The user has predictions + ground truth and asks to evaluate with StructuralSimilarityIndexMeasure, or
mentions torchmetrics.StructuralSimilarityIndexMeasure directly, or wants the standard torchmetrics implementation.
Reference signature
from torchmetrics import StructuralSimilarityIndexMeasure
# _StructuralSimilarityIndexMeasure(gaussian_kernel: bool = True, sigma: Union[float, collections.abc.Sequence[float]] = 1.5, kernel_size: Union[int, collections.abc.Sequence[int]] = 11, reduction: Literal['elementwise_mean', 'sum', 'none', None] = 'elementwise_mean', data_range: Union[float, tuple[float, float], NoneType] = None, k1: float = 0.01, k2: float = 0.03, return_full_image: bool = False, return_contrast_sensitivity: bool = False, **kwargs: Any) -> None
Library docstring
Wrapper for deprecated import.
>>> import torch
>>> preds = torch.rand([3, 3, 256, 256])
>>> target = preds * 0.75
>>> ssim = _StructuralSimilarityIndexMeasure(data_range=1.0)
>>> ssim(preds, target)
tensor(0.9219)
Quick recipe
import torchmetrics as _m
score = _m.StructuralSimilarityIndexMeasure(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).