import torch


def random_verts2D_deviation(vertices, delta_verts2d_dev_range=[-0.01, 0.01]):
    """
    Randomly add 2D uniform noise to vertices to create silhouettes/part segmentations with
    corrupted edges.
    :param vertices: (bs, 6890, 3)
    :param delta_verts2d_dev_range: range of uniform noise.
    """
    batch_size = vertices.shape[0]
    num_verts = vertices.shape[1]
    device = vertices.device

    noisy_vertices = vertices.clone()

    l, h = delta_verts2d_dev_range
    delta_verts2d_dev = (h - l) * torch.rand(batch_size, num_verts, 2, device=device) + l
    noisy_vertices[:, :, :2] = noisy_vertices[:, :, :2] + delta_verts2d_dev

    return noisy_vertices