Optical flow#

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

Calculate 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}}\]
Convention:
  • Flow is channel-last, \((*, 2)\) such as \((B, H, W, 2)\), in the units of the flow (pixels for optical flow). Permute a channel-first \((B, 2, H, W)\) flow to \((B, H, W, 2)\) first: it raises unless \(W = 2\), where it is read wrongly. Losses and metrics ports RAFT’s endpoint error.

  • The endpoint error is the Euclidean distance between the two vectors at every position, symmetric in input and target and not normalized by the image size. reduction='mean' (the default) averages it over every position of every sample at once and 'sum' adds it up, both into a 0-d tensor; 'none' returns the \((*)\) map. There is no valid mask: mask sparse ground truth on the 'none' map. An unknown reduction raises NotImplementedError.

  • aepe() and average_endpoint_error() are the same function.

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 0-d tensor, or the endpoint-error map of shape \((*)\) for reduction='none'.

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

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

Calculate 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}}\]
Convention:
  • Flow is channel-last, \((*, 2)\) such as \((B, H, W, 2)\), in the units of the flow (pixels for optical flow). Permute a channel-first \((B, 2, H, W)\) flow to \((B, H, W, 2)\) first: it raises unless \(W = 2\), where it is read wrongly. Losses and metrics ports RAFT’s endpoint error.

  • The endpoint error is the Euclidean distance between the two vectors at every position, symmetric in input and target and not normalized by the image size. reduction='mean' (the default) averages it over every position of every sample at once and 'sum' adds it up, both into a 0-d tensor; 'none' returns the \((*)\) map. There is no valid mask: mask sparse ground truth on the 'none' map. An unknown reduction raises NotImplementedError.

  • aepe() and average_endpoint_error() are the same function.

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 0-d tensor, or the endpoint-error map of shape \((*)\) for reduction='none'.

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}}\]
Convention:

See the Convention block of aepe(), which this module calls with its reduction.

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: \(()\) for 'mean' and 'sum', \((*)\) for 'none'.

Examples

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