class_docstr: Crops or pads the features to have uniform shapes.
class_docstr_tok: ["Crops","or","pads","the","features","to","have","uniform","shapes","."]
code: def apply_boxes(
      self, boxes: tf.Tensor, image_size: transforms.SizeTuple
  ) -> tf.Tensor:
      if self.size is not None:
          # Pad and crop the spatial dimensions:
          if self.allow_crop:
              # After cropping, the image shape is always [self.size, self.size]:
              processed_image_size = [self.size, self.size]
          else:
              # If only padding is performed, the image size is at least self.size:
              processed_image_size = tf.maximum(image_size, self.size)
          boxes = transforms.crop_or_pad_boxes(
              boxes,
              top=0,
              left=0,
              height=processed_image_size[0],
              width=processed_image_size[1],
              h_orig=image_size[0],
              w_orig=image_size[1],
          )
  
      # Pad or crop the number of instances:
      paddings = [[0, self.num_instances - tf.shape(boxes)[0]], [0, 0]]
      if self.allow_crop:
          paddings = tf.maximum(paddings, 0)
      boxes = tf.pad(boxes, tf.stack(paddings), constant_values=-1.0)
      if self.allow_crop:
          boxes = boxes[: self.num_instances]
          boxes.set_shape((self.num_instances, 4))
      return boxes
  
imports: import abc
  import dataclasses
  from typing import Optional, Sequence, Tuple, Union
  from clu import preprocess_spec
  from scenic.projects.owl_vit.preprocessing import modalities
  from scenic.projects.owl_vit.preprocessing import transforms
  import tensorflow
label_desc: Use image node_id 2 for calling the CropOrPad obj's underlying member method code with example usage: obj.apply_boxes(boxes, image_size) and returns: boxes