def load_pascalvoc_instances(name: str, dirname: str, mode: str, split: str):
    """
    Load Pascal VOC detection annotations to Detectron2 format.

    Args:
        dirname: Contain "Annotations", "ImageSets", "JPEGImages"
        split (str): one of "train", "test", "val", "trainval"
        class_names: list or tuple of class names
    """
    with PathManager.open(os.path.join(dirname, 'ImageSets', 'Segmentation', split + ".txt")) as f:
        fileids = np.loadtxt(f, dtype=np.str)

    dicts = []
    for field in fileids:
        anno_path = os.path.join(dirname, "Annotations", "{}.xml".format(field))
        image_path = os.path.join(dirname, "JPEGImages", "{}.jpg".format(field))
        inst_path = os.path.join(dirname, "SegmentationObject", "{}.png".format(field))
        semseg_path = os.path.join(dirname, "SegmentationClass", "{}.png".format(field))

        instances_mask = cv2.imread(inst_path)
        instances_mask = cv2.cvtColor(instances_mask, cv2.COLOR_BGR2GRAY).astype(np.int32)

        objects_ids = np.unique(instances_mask)
        objects_ids = [x for x in objects_ids if x != 0 and x != 220]

        slice_size = 5
        for i in range(0, len(objects_ids), slice_size):
            r = {
                "file_name": image_path,
                "inst_name": inst_path,
                "semseg_name": semseg_path,
                "objects_ids": objects_ids[i:i+slice_size],
            }
            dicts.append(r)
    return dicts

    Load Pascal VOC detection annotations to Detectron2 format.

    Args:
        dirname: Contain "Annotations", "ImageSets", "JPEGImages"
        split (str): one of "train", "test", "val", "trainval"
        class_names: list or tuple of class names
    
datasets/registration/register_pascalvoc_eval.py