import torch


def get_grid(size):
    """
    generate normalized pixel coordinates with [b, h, w, 2]
    :param size: tensor size
    :return: normalized pixel coordinates
    """
    b, h, w, c = size
    hori = torch.linspace(-1.0, 1.0, w).view(1, 1, 1, w).expand(b, -1, h, -1)
    vert = torch.linspace(-1.0, 1.0, h).view(1, 1, h, 1).expand(b, -1, -1, w)
    grid = torch.cat([hori, vert], dim=1).permute([0, 2, 3, 1])
    return grid