class_docstr: Resize the input image to the given size
class_docstr_tok: ["Resize","the","input","image","to","the","given","size"]
code: def forward(
      self,
      img: torch.Tensor,
      target: Optional[np.ndarray] = None,
  ) -> Union[torch.Tensor, Tuple[torch.Tensor, np.ndarray]]:
      if isinstance(self.size, int):
          target_ratio = img.shape[-2] / img.shape[-1]
      else:
          target_ratio = self.size[0] / self.size[1]
      actual_ratio = img.shape[-2] / img.shape[-1]
  
      if not self.preserve_aspect_ratio or (
          target_ratio == actual_ratio
          and (isinstance(self.size, (tuple, list)))
      ):
          # If we don't preserve the aspect ratio or the wanted aspect ratio is the same than the original one
          # We can use with the regular resize
          if target is not None:
              return super().forward(img), target
          return super().forward(img)
      else:
          # Resize
          if isinstance(self.size, (tuple, list)):
              if actual_ratio > target_ratio:
                  tmp_size = (
                      self.size[0],
                      max(int(self.size[0] / actual_ratio), 1),
                  )
              else:
                  tmp_size = (
                      max(int(self.size[1] * actual_ratio), 1),
                      self.size[1],
                  )
          elif isinstance(
              self.size, int
          ):  # self.size is the longest side, infer the other
              if img.shape[-2] <= img.shape[-1]:
                  tmp_size = (
                      max(int(self.size * actual_ratio), 1),
                      self.size,
                  )
              else:
                  tmp_size = (
                      self.size,
                      max(int(self.size / actual_ratio), 1),
                  )
  
          # Scale image
          img = F.resize(
              img, tmp_size, self.interpolation, antialias=True
          )
          raw_shape = img.shape[-2:]
          if isinstance(self.size, (tuple, list)):
              # Pad (inverted in pytorch)
              _pad = (
                  0,
                  self.size[1] - img.shape[-1],
                  0,
                  self.size[0] - img.shape[-2],
              )
              if self.symmetric_pad:
                  half_pad = (
                      math.ceil(_pad[1] / 2),
                      math.ceil(_pad[3] / 2),
                  )
                  _pad = (
                      half_pad[0],
                      _pad[1] - half_pad[0],
                      half_pad[1],
                      _pad[3] - half_pad[1],
                  )
              img = pad(img, _pad)
  
          # In case boxes are provided, resize boxes if needed (for detection task if preserve aspect ratio)
          if target is not None:
              if self.preserve_aspect_ratio:
                  # Get absolute coords
                  if target.shape[1:] == (4,):
                      if (
                          isinstance(self.size, (tuple, list))
                          and self.symmetric_pad
                      ):
                          if np.max(target) <= 1:
                              offset = (
                                  half_pad[0] / img.shape[-1],
                                  half_pad[1] / img.shape[-2],
                              )
                          target[:, [0, 2]] = (
                              offset[0]
                              + target[:, [0, 2]]
                              * raw_shape[-1]
                              / img.shape[-1]
                          )
                          target[:, [1, 3]] = (
                              offset[1]
                              + target[:, [1, 3]]
                              * raw_shape[-2]
                              / img.shape[-2]
                          )
                      else:
                          target[:, [0, 2]] *= (
                              raw_shape[-1] / img.shape[-1]
                          )
                          target[:, [1, 3]] *= (
                              raw_shape[-2] / img.shape[-2]
                          )
                  elif target.shape[1:] == (4, 2):
                      if (
                          isinstance(self.size, (tuple, list))
                          and self.symmetric_pad
                      ):
                          if np.max(target) <= 1:
                              offset = (
                                  half_pad[0] / img.shape[-1],
                                  half_pad[1] / img.shape[-2],
                              )
                          target[..., 0] = (
                              offset[0]
                              + target[..., 0]
                              * raw_shape[-1]
                              / img.shape[-1]
                          )
                          target[..., 1] = (
                              offset[1]
                              + target[..., 1]
                              * raw_shape[-2]
                              / img.shape[-2]
                          )
                      else:
                          target[..., 0] *= (
                              raw_shape[-1] / img.shape[-1]
                          )
                          target[..., 1] *= (
                              raw_shape[-2] / img.shape[-2]
                          )
                  else:
                      raise AssertionError
              return img, target
  
          return img
  
imports: import math
  from typing import Any, Dict, Optional, Tuple, Union
  import numpy
  import torch
  from PIL.Image import Image
  from torch.nn.functional import pad
  from torchvision.transforms import functional
  from torchvision.transforms import transforms
  from ..functional.pytorch import random_shadow
label_desc: Use image node_id 2 for calling the Resize obj's underlying member method code with example usage: obj.forward(img, target) and returns: super, img, super,  target, img,  target