code: def crop_or_pad_boxes(
      boxes: tf.Tensor,
      top: int,
      left: int,
      height: int,
      width: int,
      h_orig: tf.Tensor,
      w_orig: tf.Tensor,
  ):
      """Transforms the relative box coordinates according to the frame crop.
  
      Note that, if height/width are larger than h_orig/w_orig, this function
      implements the equivalent of padding.
  
      Args:
        boxes: Tensor of bounding boxes with shape (..., 4).
        top: Top of crop box in absolute pixel coordinates.
        left: Left of crop box in absolute pixel coordinates.
        height: Height of crop box in absolute pixel coordinates.
        width: Width of crop box in absolute pixel coordinates.
        h_orig: Original image height in absolute pixel coordinates.
        w_orig: Original image width in absolute pixel coordinates.
      Returns:
        Boxes tensor with same shape as input boxes but updated values.
      """
      # Bounding boxes: [num_instances, 4]
      assert len(boxes.shape) == 2
      assert boxes.shape[-1] == 4
      seq_len = tf.shape(boxes)[0]
      not_padding = tf.reduce_any(boxes != PADDING_VALUE, axis=-1)
  
      # Transform the box coordinates.
      a = tf.cast(tf.stack([h_orig, w_orig]), tf.float32)
      b = tf.cast(tf.stack([top, left]), tf.float32)
      c = tf.cast(tf.stack([height, width]), tf.float32)
      boxes = tf.reshape(
          (tf.reshape(boxes, (seq_len, 1, 2, 2)) * a - b) / c,
          (seq_len, 1, 4),
      )
  
      # Filter the valid boxes.
      boxes = tf.minimum(tf.maximum(boxes, 0.0), 1.0)
      boxes = tf.reshape(boxes, (seq_len, 4))
      boxes = tf.where(
          not_padding[..., tf.newaxis], boxes, PADDING_VALUE
      )
  
      return boxes
  
file_path: scenic/scenic/projects/owl_vit/preprocessing/transforms.py
imports: from typing import Any, Optional, Sequence, Tuple, Union
  import tensorflow
label_desc: Use image node_id 7 for calling a global function with example usage: crop_or_pad_boxes(boxes, top, left, height, width, h_orig, w_orig) and returns: boxes