def ExportGroundtruthToCOCO(image_ids, groundtruth_boxes, groundtruth_classes, categories, output_path=None):
    'Export groundtruth detection annotations in numpy arrays to COCO API.\n\n  This function converts a set of groundtruth detection annotations represented\n  as numpy arrays to dictionaries that can be ingested by the COCO API.\n  Inputs to this function are three lists: image ids for each groundtruth image,\n  groundtruth boxes for each image and groundtruth classes respectively.\n  Note that the image_ids provided here must match the ones given to the\n  ExportDetectionsToCOCO function in order for evaluation to work properly.\n  We assume that for each image, boxes, scores and classes are in\n  correspondence --- that is: image_id[i], groundtruth_boxes[i, :] and\n  groundtruth_classes[i] are associated with the same groundtruth annotation.\n\n  In the exported result, "area" fields are always set to the area of the\n  groundtruth bounding box and "iscrowd" fields are always set to 0.\n  TODO(jonathanhuang): pass in "iscrowd" array for evaluating on COCO dataset.\n\n  Args:\n    image_ids: a list of unique image identifier either of type integer or\n      string.\n    groundtruth_boxes: list of numpy arrays with shape [num_gt_boxes, 4]\n      (note that num_gt_boxes can be different for each entry in the list)\n    groundtruth_classes: list of numpy arrays (int) with shape [num_gt_boxes]\n      (note that num_gt_boxes can be different for each entry in the list)\n    categories: a list of dictionaries representing all possible categories.\n        Each dict in this list has the following keys:\n          \'id\': (required) an integer id uniquely identifying this category\n          \'name\': (required) string representing category name\n            e.g., \'cat\', \'dog\', \'pizza\'\n          \'supercategory\': (optional) string representing the supercategory\n            e.g., \'animal\', \'vehicle\', \'food\', etc\n    output_path: (optional) path for exporting result to JSON\n  Returns:\n    dictionary that can be read by COCO API\n  Raises:\n    ValueError: if (1) groundtruth_boxes and groundtruth_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])
    groundtruth_export_list = []
    image_export_list = []
    if (not (len(image_ids) == len(groundtruth_boxes) == len(groundtruth_classes))):
        raise ValueError('Input lists must have the same length')
    annotation_id = 1
    for (image_id, boxes, classes) in zip(image_ids, groundtruth_boxes, groundtruth_classes):
        image_export_list.append({'id': image_id})
        groundtruth_export_list.extend(ExportSingleImageGroundtruthToCoco(image_id, annotation_id, category_id_set, boxes, classes))
        num_boxes = classes.shape[0]
        annotation_id += num_boxes
    groundtruth_dict = {'annotations': groundtruth_export_list, 'images': image_export_list, 'categories': categories}
    if output_path:
        with tf.gfile.GFile(output_path, 'w') as fid:
            json_utils.Dump(groundtruth_dict, fid, float_digits=4, indent=2)
    return groundtruth_dict
Export groundtruth detection annotations in numpy arrays to COCO API.

This function converts a set of groundtruth detection annotations represented
as numpy arrays to dictionaries that can be ingested by the COCO API.
Inputs to this function are three lists: image ids for each groundtruth image,
groundtruth boxes for each image and groundtruth classes respectively.
Note that the image_ids provided here must match the ones given to the
ExportDetectionsToCOCO function in order for evaluation to work properly.
We assume that for each image, boxes, scores and classes are in
correspondence --- that is: image_id[i], groundtruth_boxes[i, :] and
groundtruth_classes[i] are associated with the same groundtruth annotation.

In the exported result, "area" fields are always set to the area of the
groundtruth bounding box and "iscrowd" fields are always set to 0.
TODO(jonathanhuang): pass in "iscrowd" array for evaluating on COCO dataset.

Args:
  image_ids: a list of unique image identifier either of type integer or
    string.
  groundtruth_boxes: list of numpy arrays with shape [num_gt_boxes, 4]
    (note that num_gt_boxes can be different for each entry in the list)
  groundtruth_classes: list of numpy arrays (int) with shape [num_gt_boxes]
    (note that num_gt_boxes can be different for each entry in the list)
  categories: a list of dictionaries representing all possible categories.
      Each dict in this list has the following keys:
        'id': (required) an integer id uniquely identifying this category
        'name': (required) string representing category name
          e.g., 'cat', 'dog', 'pizza'
        'supercategory': (optional) string representing the supercategory
          e.g., 'animal', 'vehicle', 'food', etc
  output_path: (optional) path for exporting result to JSON
Returns:
  dictionary that can be read by COCO API
Raises:
  ValueError: if (1) groundtruth_boxes and groundtruth_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 ExportGroundtruthToCOCO(image_ids, groundtruth_boxes, groundtruth_classes, categories, output_path=None):
    'Export groundtruth detection annotations in numpy arrays to COCO API.\n\n  This function converts a set of groundtruth detection annotations represented\n  as numpy arrays to dictionaries that can be ingested by the COCO API.\n  Inputs to this function are three lists: image ids for each groundtruth image,\n  groundtruth boxes for each image and groundtruth classes respectively.\n  Note that the image_ids provided here must match the ones given to the\n  ExportDetectionsToCOCO function in order for evaluation to work properly.\n  We assume that for each image, boxes, scores and classes are in\n  correspondence --- that is: image_id[i], groundtruth_boxes[i, :] and\n  groundtruth_classes[i] are associated with the same groundtruth annotation.\n\n  In the exported result, "area" fields are always set to the area of the\n  groundtruth bounding box and "iscrowd" fields are always set to 0.\n  TODO(jonathanhuang): pass in "iscrowd" array for evaluating on COCO dataset.\n\n  Args:\n    image_ids: a list of unique image identifier either of type integer or\n      string.\n    groundtruth_boxes: list of numpy arrays with shape [num_gt_boxes, 4]\n      (note that num_gt_boxes can be different for each entry in the list)\n    groundtruth_classes: list of numpy arrays (int) with shape [num_gt_boxes]\n      (note that num_gt_boxes can be different for each entry in the list)\n    categories: a list of dictionaries representing all possible categories.\n        Each dict in this list has the following keys:\n          \'id\': (required) an integer id uniquely identifying this category\n          \'name\': (required) string representing category name\n            e.g., \'cat\', \'dog\', \'pizza\'\n          \'supercategory\': (optional) string representing the supercategory\n            e.g., \'animal\', \'vehicle\', \'food\', etc\n    output_path: (optional) path for exporting result to JSON\n  Returns:\n    dictionary that can be read by COCO API\n  Raises:\n    ValueError: if (1) groundtruth_boxes and groundtruth_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])
    groundtruth_export_list = []
    image_export_list = []
    if (not (len(image_ids) == len(groundtruth_boxes) == len(groundtruth_classes))):
        raise ValueError('Input lists must have the same length')
    annotation_id = 1
    for (image_id, boxes, classes) in zip(image_ids, groundtruth_boxes, groundtruth_classes):
        image_export_list.append({'id': image_id})
        groundtruth_export_list.extend(ExportSingleImageGroundtruthToCoco(image_id, annotation_id, category_id_set, boxes, classes))
        num_boxes = classes.shape[0]
        annotation_id += num_boxes
    groundtruth_dict = {'annotations': groundtruth_export_list, 'images': image_export_list, 'categories': categories}
    if output_path:
        with tf.gfile.GFile(output_path, 'w') as fid:
            json_utils.Dump(groundtruth_dict, fid, float_digits=4, indent=2)
    return groundtruth_dict