def ExportSingleImageDetectionMasksToCoco(image_id, category_id_set, detection_masks, detection_scores, detection_classes):
    'Export detection masks of a single image to COCO format.\n\n  This function converts detections represented as numpy arrays to dictionaries\n  that can be ingested by the COCO evaluation API. We assume that\n  detection_masks, detection_scores, and detection_classes are in correspondence\n  - that is: detection_masks[i, :], detection_classes[i] and detection_scores[i]\n    are associated with the same annotation.\n\n  Args:\n    image_id: unique image identifier either of type integer or string.\n    category_id_set: A set of valid class ids. Detections with classes not in\n      category_id_set are dropped.\n    detection_masks: uint8 numpy array of shape [num_detections, image_height,\n      image_width] containing detection_masks.\n    detection_scores: float numpy array of shape [num_detections] containing\n      scores for detection masks.\n    detection_classes: integer numpy array of shape [num_detections] containing\n      the classes for detection masks.\n\n  Returns:\n    a list of detection mask annotations for a single image in the COCO format.\n\n  Raises:\n    ValueError: if (1) detection_masks, detection_scores and detection_classes\n      do not have the right lengths or (2) if each of the elements inside these\n      lists do not have the correct shapes or (3) if image_ids are not integers.\n  '
    if ((len(detection_classes.shape) != 1) or (len(detection_scores.shape) != 1)):
        raise ValueError('All entries in detection_classes and detection_scoresexpected to be of rank 1.')
    num_boxes = detection_classes.shape[0]
    if (not (num_boxes == len(detection_masks) == detection_scores.shape[0])):
        raise ValueError(('Corresponding entries in detection_classes, detection_scores and detection_masks should have compatible lengths and shapes Classes length: %d.  Masks length: %d. Scores length: %d' % (detection_classes.shape[0], len(detection_masks), detection_scores.shape[0])))
    detections_list = []
    for i in range(num_boxes):
        if (detection_classes[i] in category_id_set):
            detections_list.append({'image_id': image_id, 'category_id': int(detection_classes[i]), 'segmentation': _RleCompress(detection_masks[i]), 'score': float(detection_scores[i])})
    return detections_list
Export detection masks of a single image to COCO format.

This function converts detections represented as numpy arrays to dictionaries
that can be ingested by the COCO evaluation API. We assume that
detection_masks, detection_scores, and detection_classes are in correspondence
- that is: detection_masks[i, :], detection_classes[i] and detection_scores[i]
  are associated with the same annotation.

Args:
  image_id: unique image identifier either of type integer or string.
  category_id_set: A set of valid class ids. Detections with classes not in
    category_id_set are dropped.
  detection_masks: uint8 numpy array of shape [num_detections, image_height,
    image_width] containing detection_masks.
  detection_scores: float numpy array of shape [num_detections] containing
    scores for detection masks.
  detection_classes: integer numpy array of shape [num_detections] containing
    the classes for detection masks.

Returns:
  a list of detection mask annotations for a single image in the COCO format.

Raises:
  ValueError: if (1) detection_masks, detection_scores and detection_classes
    do not have the right lengths or (2) if each of the elements inside these
    lists do not have the correct shapes or (3) if image_ids are not integers.
def ExportSingleImageDetectionMasksToCoco(image_id, category_id_set, detection_masks, detection_scores, detection_classes):
    'Export detection masks of a single image to COCO format.\n\n  This function converts detections represented as numpy arrays to dictionaries\n  that can be ingested by the COCO evaluation API. We assume that\n  detection_masks, detection_scores, and detection_classes are in correspondence\n  - that is: detection_masks[i, :], detection_classes[i] and detection_scores[i]\n    are associated with the same annotation.\n\n  Args:\n    image_id: unique image identifier either of type integer or string.\n    category_id_set: A set of valid class ids. Detections with classes not in\n      category_id_set are dropped.\n    detection_masks: uint8 numpy array of shape [num_detections, image_height,\n      image_width] containing detection_masks.\n    detection_scores: float numpy array of shape [num_detections] containing\n      scores for detection masks.\n    detection_classes: integer numpy array of shape [num_detections] containing\n      the classes for detection masks.\n\n  Returns:\n    a list of detection mask annotations for a single image in the COCO format.\n\n  Raises:\n    ValueError: if (1) detection_masks, detection_scores and detection_classes\n      do not have the right lengths or (2) if each of the elements inside these\n      lists do not have the correct shapes or (3) if image_ids are not integers.\n  '
    if ((len(detection_classes.shape) != 1) or (len(detection_scores.shape) != 1)):
        raise ValueError('All entries in detection_classes and detection_scoresexpected to be of rank 1.')
    num_boxes = detection_classes.shape[0]
    if (not (num_boxes == len(detection_masks) == detection_scores.shape[0])):
        raise ValueError(('Corresponding entries in detection_classes, detection_scores and detection_masks should have compatible lengths and shapes Classes length: %d.  Masks length: %d. Scores length: %d' % (detection_classes.shape[0], len(detection_masks), detection_scores.shape[0])))
    detections_list = []
    for i in range(num_boxes):
        if (detection_classes[i] in category_id_set):
            detections_list.append({'image_id': image_id, 'category_id': int(detection_classes[i]), 'segmentation': _RleCompress(detection_masks[i]), 'score': float(detection_scores[i])})
    return detections_list