#185 · Computer Vision · Medium
⊣ Solve on deep-ml.comCompute the Endpoint Error (EPE) between a predicted optical flow field and a ground-truth flow field. Optionally apply a binary validity mask so that only valid pixels contribute to the mean EPE.
import numpy as np
def optical_flow_epe(pred_flow: np.ndarray, gt_flow: np.ndarray,
mask: np.ndarray = None) -> float:
# pred_flow, gt_flow: (H, W, 2)
diff = pred_flow - gt_flow
epe = np.sqrt(np.sum(diff ** 2, axis=-1)) # (H, W)
if mask is not None:
mask = mask.astype(bool)
if mask.sum() == 0:
return 0.0
return float(np.mean(epe[mask]))
return float(np.mean(epe))True and average their EPE values.