def ExportDetectionsToCOCO(image_ids, detection_boxes, detection_scores, detection_classes, categories, output_path=None):
    "Export detection annotations in numpy arrays to COCO API.\n\n  This function converts a set of predicted detections represented\n  as numpy arrays to dictionaries that can be ingested by the COCO API.\n  Inputs to this function are lists, consisting of boxes, scores and\n  classes, respectively, corresponding to each image for which detections\n  have been produced.  Note that the image_ids provided here must\n  match the ones given to the ExportGroundtruthToCOCO function in order\n  for evaluation to work properly.\n\n  We assume that for each image, boxes, scores and classes are in\n  correspondence --- that is: detection_boxes[i, :], detection_scores[i] and\n  detection_classes[i] are associated with the same detection.\n\n  Args:\n    image_ids: a list of unique image identifier either of type integer or\n      string.\n    detection_boxes: list of numpy arrays with shape [num_detection_boxes, 4]\n    detection_scores: list of numpy arrays (float) with shape\n      [num_detection_boxes]. Note that num_detection_boxes can be different\n      for each entry in the list.\n    detection_classes: list of numpy arrays (int) with shape\n      [num_detection_boxes]. Note that num_detection_boxes can be different\n      for each entry in the list.\n    categories: a list of dictionaries representing all possible categories.\n      Each dict in this list must have an integer 'id' key uniquely identifying\n      this category.\n    output_path: (optional) path for exporting result to JSON\n\n  Returns:\n    list of dictionaries that can be read by COCO API, where each entry\n    corresponds to a single detection and has keys from:\n    ['image_id', 'category_id', 'bbox', 'score'].\n  Raises:\n    ValueError: if (1) detection_boxes and detection_classes do not have the\n      right lengths or (2) if each of the elements inside these lists do not\n      have the correct shapes or (3) if image_ids are not integers.\n  "
    category_id_set = set([cat['id'] for cat in categories])
    detections_export_list = []
    if (not (len(image_ids) == len(detection_boxes) == len(detection_scores) == len(detection_classes))):
        raise ValueError('Input lists must have the same length')
    for (image_id, boxes, scores, classes) in zip(image_ids, detection_boxes, detection_scores, detection_classes):
        detections_export_list.extend(ExportSingleImageDetectionBoxesToCoco(image_id, category_id_set, boxes, scores, classes))
    if output_path:
        with tf.gfile.GFile(output_path, 'w') as fid:
            json_utils.Dump(detections_export_list, fid, float_digits=4, indent=2)
    return detections_export_list
Export detection annotations in numpy arrays to COCO API.

This function converts a set of predicted detections represented
as numpy arrays to dictionaries that can be ingested by the COCO API.
Inputs to this function are lists, consisting of boxes, scores and
classes, respectively, corresponding to each image for which detections
have been produced.  Note that the image_ids provided here must
match the ones given to the ExportGroundtruthToCOCO function in order
for evaluation to work properly.

We assume that for each image, boxes, scores and classes are in
correspondence --- that is: detection_boxes[i, :], detection_scores[i] and
detection_classes[i] are associated with the same detection.

Args:
  image_ids: a list of unique image identifier either of type integer or
    string.
  detection_boxes: list of numpy arrays with shape [num_detection_boxes, 4]
  detection_scores: list of numpy arrays (float) with shape
    [num_detection_boxes]. Note that num_detection_boxes can be different
    for each entry in the list.
  detection_classes: list of numpy arrays (int) with shape
    [num_detection_boxes]. Note that num_detection_boxes can be different
    for each entry in the list.
  categories: a list of dictionaries representing all possible categories.
    Each dict in this list must have an integer 'id' key uniquely identifying
    this category.
  output_path: (optional) path for exporting result to JSON

Returns:
  list of dictionaries that can be read by COCO API, where each entry
  corresponds to a single detection and has keys from:
  ['image_id', 'category_id', 'bbox', 'score'].
Raises:
  ValueError: if (1) detection_boxes 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 ExportDetectionsToCOCO(image_ids, detection_boxes, detection_scores, detection_classes, categories, output_path=None):
    "Export detection annotations in numpy arrays to COCO API.\n\n  This function converts a set of predicted detections represented\n  as numpy arrays to dictionaries that can be ingested by the COCO API.\n  Inputs to this function are lists, consisting of boxes, scores and\n  classes, respectively, corresponding to each image for which detections\n  have been produced.  Note that the image_ids provided here must\n  match the ones given to the ExportGroundtruthToCOCO function in order\n  for evaluation to work properly.\n\n  We assume that for each image, boxes, scores and classes are in\n  correspondence --- that is: detection_boxes[i, :], detection_scores[i] and\n  detection_classes[i] are associated with the same detection.\n\n  Args:\n    image_ids: a list of unique image identifier either of type integer or\n      string.\n    detection_boxes: list of numpy arrays with shape [num_detection_boxes, 4]\n    detection_scores: list of numpy arrays (float) with shape\n      [num_detection_boxes]. Note that num_detection_boxes can be different\n      for each entry in the list.\n    detection_classes: list of numpy arrays (int) with shape\n      [num_detection_boxes]. Note that num_detection_boxes can be different\n      for each entry in the list.\n    categories: a list of dictionaries representing all possible categories.\n      Each dict in this list must have an integer 'id' key uniquely identifying\n      this category.\n    output_path: (optional) path for exporting result to JSON\n\n  Returns:\n    list of dictionaries that can be read by COCO API, where each entry\n    corresponds to a single detection and has keys from:\n    ['image_id', 'category_id', 'bbox', 'score'].\n  Raises:\n    ValueError: if (1) detection_boxes and detection_classes do not have the\n      right lengths or (2) if each of the elements inside these lists do not\n      have the correct shapes or (3) if image_ids are not integers.\n  "
    category_id_set = set([cat['id'] for cat in categories])
    detections_export_list = []
    if (not (len(image_ids) == len(detection_boxes) == len(detection_scores) == len(detection_classes))):
        raise ValueError('Input lists must have the same length')
    for (image_id, boxes, scores, classes) in zip(image_ids, detection_boxes, detection_scores, detection_classes):
        detections_export_list.extend(ExportSingleImageDetectionBoxesToCoco(image_id, category_id_set, boxes, scores, classes))
    if output_path:
        with tf.gfile.GFile(output_path, 'w') as fid:
            json_utils.Dump(detections_export_list, fid, float_digits=4, indent=2)
    return detections_export_list