spatialcorrelationcoefficient
Metric
SpatialCorrelationCoefficientfromtorchmetrics(torchmetrics.image.SpatialCorrelationCoefficient)
When to invoke this skill
The user has predictions + ground truth and asks to evaluate with SpatialCorrelationCoefficient, or
mentions torchmetrics.image.SpatialCorrelationCoefficient directly, or wants the standard torchmetrics implementation.
Reference signature
from torchmetrics.image import SpatialCorrelationCoefficient
# SpatialCorrelationCoefficient(high_pass_filter: Optional[torch.Tensor] = None, window_size: int = 8, **kwargs: Any) -> None
Library docstring
Compute Spatial Correlation Coefficient (SCC_).
As input to ``forward`` and ``update`` the metric accepts the following input
- ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)`` or ``(N,H,W)``.
- ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)`` or ``(N,H,W)``.
As output of `forward` and `compute` the metric returns the following output
- ``scc`` (:class:`~torch.Tensor`): Tensor with scc score
Args:
hp_filter: High-pass filter tensor. default: tensor([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]).
window_size: Local window size integer. default: 8.
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
Example:
>>> from torch import randn
>>> from torchmetrics.image import SpatialCorrelationCoefficient as SCC
>>> preds = randn([32, 3, 64, 64])
>>> target = randn([32, 3, 64, 64])
>>> scc = SCC()
>>> scc(preds, target)
tensor(0.0023)
Quick recipe
import torchmetrics.image as _m
score = _m.SpatialCorrelationCoefficient(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).