def METHOD_NAME(args):
    dataset, idx = args
    # IMAGE DATA
    img_id = idx + 1
    image = {}
    # Official COCO "images" entries have these fields
    # 'license', 'url', 'file_name', 'height', 'width', 'date_captured', 'id'
    img, target, ret_idx = dataset[idx]
    img_info = dataset.get_img_info(idx)
    assert isinstance(img_info, dict)
    image.update(img_info)
    image["width"], image["height"] = target.size
    if "id" not in image.keys():
        # Start indexing from 1 if "id" field is not present
        image["id"] = img_id
    else:
        img_id = image["id"]
    # ANNOTATION DATA
    per_img_annotations = []
    # Official COCO "annotations" entries have these fields
    # 'segmentation', 'area', 'iscrowd', 'image_id', 'bbox', 'category_id', 'id'
    #
    assert ret_idx == idx, (ret_idx, idx)
    assert isinstance(target, BoxList)
    bboxes = target.convert("xywh").bbox.tolist()
    segm_available = "masks" in target.fields()
    if segm_available:
        masks = target.get_field("masks").get_mask_tensor()  # [N, H, W]
        if masks.dim() == 2:
            masks = masks.unsqueeze(0)
        rles = masks_to_rles(masks)
        """
        !!!WARNING!!!
        At this point the area value differs from the precomputed
        original COCO area values, because we compute the area
        by counting the nonzero entries of the binary mask
        while COCO areas are computed directly from the polygons
        Example:
        Reference image data
        {'license': 2,
         'url': 'http://farm9.staticflickr.com/8035/8024364858_9c41dc1666_z.jpg',
         'file_name': 'COCO_val2014_000000000139.jpg',
         'height': 426,
         'width': 640,
         'date_captured': '2013-11-21 01:34:01',
         'id': 139}
        Original COCO area values
        [  531.8071, 13244.6572,  5833.1182,  2245.3435,  1833.7841,  1289.3734,
           210.1482,  2913.1104,   435.1450,   217.7192,  2089.9749,   338.6089,
           322.5936,   225.6642,  2171.6189,   178.1851,    90.9873,   189.5601,
           120.2320,  2362.4897]
        Area values using the binary masks
        [  531, 13247,  5846,  2251,  1850,  1292,   212,  2922,   439,   224,
           2060,   342,   324,   226,  2171,   178,    90,   187,   120,  2372]
        """
        areas = (masks != 0).sum([1, 2]).tolist()
    else:
        areas = target.area().tolist()
    cat_ids = target.get_field("labels").long().tolist()
    assert len(bboxes) == len(areas) == len(cat_ids)
    num_instances = len(target)
    for ann_idx in range(num_instances):
        annotation = {}
        if segm_available:
            annotation["segmentation"] = rles[ann_idx]
        annotation["area"] = areas[ann_idx]
        annotation["iscrowd"] = 0
        annotation["image_id"] = img_id
        annotation["bbox"] = bboxes[ann_idx]
        annotation["category_id"] = cat_ids[ann_idx]
        per_img_annotations.append(annotation)
    return image, per_img_annotations