Optical Flow EPE with Masks (OmniWorld-style metric)

Detection, Video & Advanced Vision DS practice problem on Onlearn.

Difficulty: hard.

Topics: Understanding Masked End-Point Error (EPE) for Optical Flow Evaluation, End-Point Error (EPE), Euclidean Distance Field, Boolean Masking, Vectorized Array Operations, Mean Absolute Error (MAE) variants, Computer Vision, Linear Algebra, Vector Calculus, Performance Optimization, Statistical Analysis, Optical Flow Estimation, Metric Evaluation, Pixel-wise Operations, Array Masking, Error Analysis.

Implement a function 'calculate masked epe' that computes the End Point Error (EPE) between two optical flow fields (predicted and ground truth). The function must only consider pixels where the 'valid mask' is set to 1. The EPE is defined as the L2 norm of the difference vector at each pixel. If no pixels are valid, the function should return 0.0.