def kpt_flip(kpts, img_shape, flip_pairs, direction):
    """Flip keypoints horizontally or vertically.

    Args:
        kpts (Tensor): Shape (..., 2)
        img_shape (tuple): Image shape.
        flip_pairs (list): Flip pair index.
        direction (str): Flip direction, only "horizontal" is supported now.
            Default: "horizontal"

    Returns:
        Tensor: Flipped bboxes.
    """
    assert kpts.shape[-1] % 2 == 0
    assert direction == 'horizontal'
    flipped = kpts.clone()
    flipped[..., 0] = img_shape[1] - flipped[..., 0]
    for pair in flip_pairs:
        flipped[:, pair, :] = flipped[:, pair[::-1], :]
    return flipped