Optical flow#

kornia.metrics.aepe(input, target, reduction='mean')[source]#

Create a function that calculates the average endpoint error (AEPE) between 2 flow maps.

AEPE is the endpoint error between two 2D vectors (e.g., optical flow). Given a h x w x 2 optical flow map, the AEPE is:

\[\text{AEPE}=\frac{1}{hw}\sum_{i=1, j=1}^{h, w}\sqrt{(I_{i,j,1}-T_{i,j,1})^{2}+(I_{i,j,2}-T_{i,j,2})^{2}}\]
Parameters:
  • input (Tensor) – the input flow map with shape \((*, 2)\).

  • target (Tensor) – the target flow map with shape \((*, 2)\).

  • reduction (str, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Default: "mean"

Return type:

Tensor

Returns:

the computed AEPE as a scalar.

Examples

>>> ones = torch.ones(4, 4, 2)
>>> aepe(ones, 1.2 * ones)
tensor(0.2828)
Reference:

https://link.springer.com/content/pdf/10.1007/s11263-010-0390-2.pdf

class kornia.metrics.AEPE(reduction='mean')[source]#

Computes the average endpoint error (AEPE) between 2 flow maps.

EPE is the endpoint error between two 2D vectors (e.g., optical flow). Given a h x w x 2 optical flow map, the AEPE is:

\[\text{AEPE}=\frac{1}{hw}\sum_{i=1, j=1}^{h, w}\sqrt{(I_{i,j,1}-T_{i,j,1})^{2}+(I_{i,j,2}-T_{i,j,2})^{2}}\]
Parameters:

reduction (str, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Default: "mean"

Shape:
  • input: \((*, 2)\).

  • target \((*, 2)\).

  • output: \((1)\).

Examples

>>> input1 = torch.rand(1, 4, 5, 2)
>>> input2 = torch.rand(1, 4, 5, 2)
>>> epe = AEPE(reduction="mean")
>>> epe = epe(input1, input2)