def cvat_rle_to_dm_rle(shape, img_h: int, img_w: int) -> dm.RleMask:
        "Converts a CVAT RLE to a Datumaro / COCO mask"

        # use COCO representation of CVAT RLE to avoid python loops
        left, top, right, bottom = [math.trunc(v) for v in shape.points[-4:]]
        h = bottom - top + 1
        w = right - left + 1
        cvat_as_coco_rle_uncompressed = {
            "counts": shape.points[:-4],
            "size": [w, h],
        }
        cvat_as_coco_rle_compressed = mask_utils.frPyObjects(
            [cvat_as_coco_rle_uncompressed], h=h, w=w
        )[0]

        # expand the mask to the full image size
        tight_mask = mask_utils.decode(cvat_as_coco_rle_compressed).transpose()
        full_mask = np.zeros((img_h, img_w), dtype=np.uint8)
        full_mask[top : bottom + 1, left : right + 1] = tight_mask

        # obtain RLE
        coco_rle = mask_utils.encode(np.asfortranarray(full_mask))
        return dm.RleMask(
            rle=coco_rle,
            label=shape.label,
            z_order=shape.z_order,
            attributes=shape.attributes,
            group=shape.group,
        )
Converts a CVAT RLE to a Datumaro / COCO mask
cvat/apps/dataset_manager/formats/transformations.py