Implementation:Kornia Kornia Geman Mcclure Loss
| Knowledge Sources | |
|---|---|
| Domains | Vision, Loss_Functions |
| Last Updated | 2026-02-09 15:00 GMT |
Overview
Geman-McClure Loss is a robust regression loss function that saturates for large residuals, providing strong outlier rejection.
Description
The Geman-McClure loss, originally proposed for Bayesian image analysis (Geman and McClure, 1985), is a robust loss function that completely saturates for very large residuals, effectively ignoring outliers entirely. It is part of the family of robust estimators described by Barron (2019).
The mathematical formulation is:
Where is the prediction and is the target. The loss is bounded between 0 and 2, meaning that no matter how large the residual becomes, the loss contribution is capped. This makes it one of the most aggressive robust loss functions available.
Usage
Import this loss for regression tasks where extreme outliers are present and should be completely ignored during training. It is particularly useful in robust estimation problems such as structure from motion, point cloud registration, and image matching where a significant portion of correspondences may be incorrect.
Code Reference
Source Location
- Repository: Kornia
- File: kornia/losses/geman_mcclure.py
- Lines: 1-134
Signature
def geman_mcclure_loss(
img1: torch.Tensor,
img2: torch.Tensor,
reduction: str = "none",
) -> torch.Tensor: ...
class GemanMcclureLoss(nn.Module):
def __init__(self, reduction: str = "none") -> None: ...
def forward(self, img1: torch.Tensor, img2: torch.Tensor) -> torch.Tensor: ...
Import
from kornia.losses import GemanMcclureLoss
from kornia.losses import geman_mcclure_loss
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| img1 | torch.Tensor | Yes | Predicted tensor with arbitrary shape (*) |
| img2 | torch.Tensor | Yes | Target tensor with the same shape as img1 |
| reduction | str | No | Reduction mode: 'none' (default), 'mean', or 'sum' |
Outputs
| Name | Type | Description |
|---|---|---|
| loss | torch.Tensor | Computed Geman-McClure loss; element-wise for 'none', scalar for 'mean'/'sum'; values bounded in [0, 2] |
Usage Examples
import torch
from kornia.losses import GemanMcclureLoss
# Create sample tensors
img1 = torch.randn(2, 3, 32, 32, requires_grad=True)
img2 = torch.randn(2, 3, 32, 32)
# Using the module API
criterion = GemanMcclureLoss(reduction="mean")
output = criterion(img1, img2)
output.backward()
# Using the functional API
from kornia.losses import geman_mcclure_loss
output = geman_mcclure_loss(img1, img2, reduction="sum")