code: def generalized_box_iou(
      boxes1: Array,
      boxes2: Array,
      np_backbone: PyModule = jnp,
      all_pairs: bool = True,
      eps: float = 1e-6,
  ) -> Array:
      """Generalized IoU from https://giou.stanford.edu/.
  
      The boxes should be in [x, y, x', y'] format specifying top-left and
      bottom-right corners.
  
      Args:
        boxes1: Predicted bounding-boxes in shape [..., n, 4].
        boxes2: Target bounding-boxes in shape [..., m, 4].
        np_backbone: Numpy module: Either the regular numpy package or jax.numpy.
        all_pairs: Whether to compute generalized IoU from between all-pairs of
          boxes or not. Note that if all_pairs == False, we must have m==n.
        eps: Epsilon for numerical stability.
  
      Returns:
        If all_pairs == True, returns a [bs, n, m] pairwise matrix, of generalized
        ious. If all_pairs == False, returns a [bs, n] matrix of generalized ious.
      """
      # Degenerate boxes gives inf / nan results, so do an early check.
      # TODO(b/166344282): Figure out how to enable asserts on inputs with jitting:
      # assert (boxes1[:, :, 2:] >= boxes1[:, :, :2]).all()
      # assert (boxes2[:, :, 2:] >= boxes2[:, :, :2]).all()
      iou, union = box_iou(
          boxes1,
          boxes2,
          np_backbone=np_backbone,
          all_pairs=all_pairs,
          eps=eps,
      )
  
      # Generalized IoU has an extra term which takes into account the area of
      # the box containing both of these boxes. The following code is very similar
      # to that for computing intersection but the min and max are flipped.
      if all_pairs:
          lt = np_backbone.minimum(
              boxes1[..., :, None, :2], boxes2[..., None, :, :2]
          )  # [bs, n, m, 2]
          rb = np_backbone.maximum(
              boxes1[..., :, None, 2:], boxes2[..., None, :, 2:]
          )  # [bs, n, m, 2]
  
      else:
          lt = np_backbone.minimum(
              boxes1[..., :, :2], boxes2[..., :, :2]
          )  # [bs, n, 2]
          rb = np_backbone.maximum(
              boxes1[..., :, 2:], boxes2[..., :, 2:]
          )  # [bs, n, 2]
  
      # Now, compute the covering box's area.
      wh = (rb - lt).clip(0.0)  # Either [bs, n, 2] or [bs, n, m, 2].
      area = wh[..., 0] * wh[..., 1]  # Either [bs, n] or [bs, n, m].
  
      # Finally, compute generalized IoU from IoU, union, and area.
      # Somehow the PyTorch implementation does not use eps to avoid 1/0 cases.
      return iou - (area - union) / (area + eps)
  
file_path: scenic/scenic/model_lib/base_models/box_utils.py
imports: from typing import Any, Union
  import jax.numpy
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: generalized_box_iou(boxes1, boxes2, np_backbone, all_pairs, eps) and returns: unknown