import megengine as mge
import megengine.functional as F
import numpy as np


def bilinear_sampler(img, coords, mode="bilinear", mask=False):
    """Wrapper for grid_sample, uses pixel coordinates"""
    H, W = img.shape[-2:]

    img = 
F.remap(img, coords, border_mode="constant")