Optical flow#

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

Compute the average endpoint error (AEPE) between two flow maps.

epe = aepe(input, target) takes two channel-last flows (*, 2), such as (B, H, W, 2), and returns the mean Euclidean distance between their vectors, in the units of the flow. For an h x w flow 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:
  • A channel-first (B, 2, H, W) flow must be permuted 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 distance is symmetric in input and target and not normalized by the image size. reduction='mean' 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.

  • Float16 and bfloat16 inputs are computed in float32 and the result is returned in their promoted dtype.

Parameters:
  • input (Tensor) – the predicted flow with shape (*, 2).

  • target (Tensor) – the ground-truth flow with the shape of input.

  • reduction (str, optional) – 'mean' (default) averages, 'sum' adds and 'none' keeps the endpoint-error map. Default: "mean"

Return type:

Tensor

Returns:

a 0-d tensor, or the map of shape (*) for reduction='none'.

See also

  • AEPE: the module form.

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]#

Compute the average endpoint error (AEPE) between two flow maps.

epe = aepe(input, target) takes two channel-last flows (*, 2), such as (B, H, W, 2), and returns the mean Euclidean distance between their vectors, in the units of the flow. For an h x w flow 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:
  • A channel-first (B, 2, H, W) flow must be permuted 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 distance is symmetric in input and target and not normalized by the image size. reduction='mean' 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.

  • Float16 and bfloat16 inputs are computed in float32 and the result is returned in their promoted dtype.

Parameters:
  • input (Tensor) – the predicted flow with shape (*, 2).

  • target (Tensor) – the ground-truth flow with the shape of input.

  • reduction (str, optional) – 'mean' (default) averages, 'sum' adds and 'none' keeps the endpoint-error map. Default: "mean"

Return type:

Tensor

Returns:

a 0-d tensor, or the map of shape (*) for reduction='none'.

See also

  • AEPE: the module form.

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]#

Compute the average endpoint error (AEPE) between two flow maps (module form).

criterion = AEPE(reduction) stores reduction, and epe = criterion(input, target) is aepe() on two (*, 2) flows.

Convention:

See the Convention block of aepe().

Parameters:

reduction (str, optional) – 'mean' (default), 'sum' or 'none', as in aepe(). Default: "mean"

Shape:
  • input: (*, 2).

  • target: (*, 2).

  • output: () for 'mean' and 'sum', (*) for 'none'.

See also

Examples

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