def get_bboxes(tokens, metadata):
  """Extracts bounding boxes relevant to the given tokens.

  Args:
    tokens: list of string tokens where objects with bounding boxes are denoted
      [OBJ-`object_id`]. `object_id` indexes in `metadata["boxes"]`.
    metadata: dictionary containing image metadata from the VCR dataset,
      including bounding boxes of referenced objects.

  Returns:
    bbox_positions_matrix: a `FLAGS.max_num_bboxes` x 4 int matrix, containing
            the first `FLAGS.max_num_bboxes` bounding boxes referenced in the
            tokens. Each row contains offset_height, offset_width,
            target_height and target_width of the bounding box.
    bbox_indices_vector: an int vector of length `len(tokens)`, containing
            the index of the bounding box relevant to each token, or -1 if no
            bounding box is referenced.
  """
  bbox_positions = {}
  bbox_indices = collections.defaultdict(list)
  for idx, t in enumerate(tokens):
    if len(bbox_positions) >= FLAGS.max_num_bboxes:
      break
    m = re.match(r"\[OBJ-(\d+)\]", t)
    if m:
      object_id = int(m.group(1))
      bbox_positions[object_id] = metadata["boxes"][object_id]
      bbox_indices[object_id].append(idx)

  # Adds dummy bounding boxes if there are fewer than `FLAGS.max_num_bboxes`.
  for idx in range(FLAGS.max_num_bboxes):
    if len(bbox_positions) == FLAGS.max_num_bboxes:
      break
    bbox_positions[-idx - 1] = [0, 0, 1, 1]

  bbox_positions_matrix = []
  bbox_indices_vector = [-1] * len(tokens)
  for idx, (object_id, bbox) in enumerate(bbox_positions.iteritems()):
    offset_height = int(bbox[1])
    offset_width = int(bbox[0])
    target_height = int(bbox[3] - bbox[1])
    target_width = int(bbox[2] - bbox[0])
    bbox_positions_matrix.extend(
        [offset_height, offset_width, target_height, target_width])
    for token_idx in bbox_indices[object_id]:
      bbox_indices_vector[token_idx] = idx

  tf.logging.info("Box positions: %s", bbox_positions_matrix)
  tf.logging.info("Box token indices: %s", bbox_indices_vector)
  return bbox_positions_matrix, bbox_indices_vector
Extracts bounding boxes relevant to the given tokens.

  Args:
    tokens: list of string tokens where objects with bounding boxes are denoted
      [OBJ-`object_id`]. `object_id` indexes in `metadata["boxes"]`.
    metadata: dictionary containing image metadata from the VCR dataset,
      including bounding boxes of referenced objects.

  Returns:
    bbox_positions_matrix: a `FLAGS.max_num_bboxes` x 4 int matrix, containing
            the first `FLAGS.max_num_bboxes` bounding boxes referenced in the
            tokens. Each row contains offset_height, offset_width,
            target_height and target_width of the bounding box.
    bbox_indices_vector: an int vector of length `len(tokens)`, containing
            the index of the bounding box relevant to each token, or -1 if no
            bounding box is referenced.
  
language/question_answering/b2t2/compute_vcr_features.py