Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kornia Kornia AEPE Metric

From Leeroopedia
Revision as of 15:20, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Kornia_Kornia_AEPE_Metric.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Vision, Metrics
Last Updated 2026-02-09 15:00 GMT

Overview

Computes the Average Endpoint Error (AEPE) between two optical flow maps, measuring the Euclidean distance between predicted and ground truth 2D flow vectors.

Description

The AEPE (Average Endpoint Error) metric calculates the average Euclidean distance between corresponding 2D flow vectors in two flow maps. Given flow maps of shape (H, W, 2), the AEPE is defined as:

AEPE = (1/HW) * sum(sqrt((I_{i,j,1} - T_{i,j,1})^2 + (I_{i,j,2} - T_{i,j,2})^2))

This is the standard evaluation metric for optical flow estimation, as established in the Middlebury optical flow benchmark. The module provides both a functional interface (aepe function) and an nn.Module-based interface (AEPE class). The function also has an alias average_endpoint_error. Three reduction modes are supported: mean (default), sum, and none.

Usage

Import this metric when evaluating optical flow estimation models. It is suitable for comparing predicted optical flow fields against ground truth flow fields from benchmarks such as Middlebury, KITTI, or Sintel.

Code Reference

Source Location

Signature

def aepe(
    input: torch.Tensor,
    target: torch.Tensor,
    reduction: str = "mean"
) -> torch.Tensor:

class AEPE(nn.Module):
    def __init__(self, reduction: str = "mean") -> None: ...
    def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor: ...

average_endpoint_error = aepe

Import

from kornia.metrics import aepe, AEPE
# or
from kornia.metrics import average_endpoint_error

I/O Contract

Inputs

Name Type Required Description
input torch.Tensor Yes The predicted flow map with shape (*, 2). The last dimension must be 2 representing the (u, v) flow components.
target torch.Tensor Yes The ground truth flow map with shape (*, 2). Must match the shape of input.
reduction str No Specifies the reduction to apply: none (no reduction), mean (average over all elements, default), or sum (sum all elements).

Outputs

Name Type Description
epe torch.Tensor The computed endpoint error. A scalar if reduction is mean or sum, or a tensor matching the spatial dimensions of the input if reduction is none.

Usage Examples

import torch
from kornia.metrics import aepe, AEPE

# Functional interface
ones = torch.ones(4, 4, 2)
error = aepe(ones, 1.2 * ones)
# error: tensor(0.2828)

# Module interface
input1 = torch.rand(1, 4, 5, 2)
input2 = torch.rand(1, 4, 5, 2)
metric = AEPE(reduction="mean")
error = metric(input1, input2)

# No reduction - get per-pixel endpoint errors
error_map = aepe(input1, input2, reduction="none")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment