def poly_2_mask(polygons, shape):
    # TODO This doesnt fill the array inplace.    out = np.zeros(shape + (len(polygons),), dtype=np.uint8)
    """
    Converts a list of polygons into a binary mask.

    @param polygons: list of polygons, where each polygon is a list of (x, y) coordinates.
    @param shape: tuple, the shape of the mask (height, width).

    @return: numpy array, binary mask of the same size as the image.
    """
    out = np.zeros(shape + (len(polygons),), dtype=np.uint8)
    for i, polygon in enumerate(polygons):
        im = Image.fromarray(out[..., i])
        d = ImageDraw.Draw(im)
        d.polygon(polygon, fill=1)
        out[..., i] = np.asarray(im)
    return out

    Converts a list of polygons into a binary mask.

    @param polygons: list of polygons, where each polygon is a list of (x, y) coordinates.
    @param shape: tuple, the shape of the mask (height, width).

    @return: numpy array, binary mask of the same size as the image.
    
python/deeplake/integrations/mmdet/mmdet_dataset_.py