def quantize_bbox(bboxes, height, width, grid_size=GRID_SIZE):
  """Transform bounding box coordinates into a position in an N x N grid.

  Args:
    bboxes: <float32> [batch, 4] Object bounding boxes, each with (x_min, y_min,
      x_max, y_max).
    height: Overall image height.
    width: Overall image width.
    grid_size: Partition image into a grid_size x grid_size raster.

  Returns:
    position: <int32> [batch] Grid index of the center of the bounding box.
              Total number of indices is grid_size * grid_size.
  """
  if max(bboxes[:, 2]) > width:
    raise ValueError("Max x should be less than width.")
  if max(bboxes[:, 3]) > height:
    return ValueError("Max y should be less than height.")
  center_x = (bboxes[:, 0] + bboxes[:, 2]) / 2
  center_y = (bboxes[:, 1] + bboxes[:, 3]) / 2
  raster_x = np.floor(center_x / width * grid_size)
  raster_y = np.floor(center_y / height * grid_size)
  position = raster_x * grid_size + raster_y
  return position.astype(np.int64)
Transform bounding box coordinates into a position in an N x N grid.

  Args:
    bboxes: <float32> [batch, 4] Object bounding boxes, each with (x_min, y_min,
      x_max, y_max).
    height: Overall image height.
    width: Overall image width.
    grid_size: Partition image into a grid_size x grid_size raster.

  Returns:
    position: <int32> [batch] Grid index of the center of the bounding box.
              Total number of indices is grid_size * grid_size.
  
language/capwap/utils/image_utils.py