class_docstr: Resizes image to a given size, adding padding to perserve the aspect ratio.
  
  Padding is added on the bottom and right.
  
  Attr:
    size: The new size of the image: either an integer H, where H is both the
      new height and width, or a tuple or list [H, W] of integers, where H and W
      are new image's height and width respectively.
    pad_value: Value to use for padding.
    antialias: Whether to use an anti-aliasing filter when downsampling an
      image.
class_docstr_tok: ["Resizes","image","to","a","given","size",",","adding","padding","to","perserve","the","aspect","ratio",".","Padding","is","added","on","the","bottom","and","right",".","Attr",":","size",":","The","new","size","of","the","image",":","either","an","integer","H",",","where","H","is","both","the","new","height","and","width",",","or","a","tuple","or","list","[","H",",","W","]","of","integers",",","where","H","and","W","are","new","image","'s","height","and","width","respectively",".","pad_value",":","Value","to","use","for","padding",".","antialias",":","Whether","to","use","an","anti-aliasing","filter","when","downsampling","an","image","."]
docstr: Applies the appropriate TF resizing function.
docstr_tok: ["Applies","the","appropriate","TF","resizing","function","."]
code: def _resize_image(
      self, image, pad_value, method=tf.image.ResizeMethod.BILINEAR
  ):
      """Applies the appropriate TF resizing function."""
      size = self.size
      if isinstance(size, int):
          size = (size, size)
      dtype = image.dtype
      num_channels = image.shape[-1]
  
      # Resize the image to fit into target size, while keeping aspect ratio:
      in_height, in_width = transforms.get_dynamic_size(
          image, tf.float32
      )
      ratio = tf.maximum(
          in_height / float(size[0]), in_width / float(size[1])
      )
      fit_height = tf.cast(
          tf.minimum(in_height / ratio, size[0]), tf.int32
      )
      fit_width = tf.cast(
          tf.minimum(in_width / ratio, size[1]), tf.int32
      )
      image = tf.image.resize(
          image,
          [fit_height, fit_width],
          method=method,
          antialias=self.antialias,
      )
  
      # Pad to the same aspect ratio as the desired size:
      paddings = transforms.get_paddings(tf.shape(image), size)
      image = tf.pad(
          image, paddings, mode="CONSTANT", constant_values=pad_value
      )
      image.set_shape(image.shape[:-3] + tuple(size) + (num_channels,))
      return tf.cast(image, dtype)
  
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 1 for calling the ResizeWithPad obj's underlying member method code with example usage: obj._resize_image(image, pad_value, method) and returns: tf