code: def _resize_image_and_masks(
      image: Tensor,
      self_min_size: float,
      self_max_size: float,
      target: Optional[Dict[str, Tensor]] = None,
      fixed_size: Optional[Tuple[int, int]] = None,
  ) -> Tuple[Tensor, Optional[Dict[str, Tensor]]]:
      if torchvision._is_tracing():
          im_shape = _get_shape_onnx(image)
      else:
          im_shape = torch.tensor(image.shape[-2:])
  
      size: Optional[List[int]] = None
      scale_factor: Optional[float] = None
      recompute_scale_factor: Optional[bool] = None
      if fixed_size is not None:
          size = [fixed_size[1], fixed_size[0]]
      else:
          min_size = torch.min(im_shape).to(
              dtype=torch.float32
          )  # 获取高宽中的最小值
          max_size = torch.max(im_shape).to(
              dtype=torch.float32
          )  # 获取高宽中的最大值
          scale = torch.min(
              self_min_size / min_size, self_max_size / max_size
          )  # 计算缩放比例
  
          if torchvision._is_tracing():
              scale_factor = _fake_cast_onnx(scale)
          else:
              scale_factor = scale.item()
          recompute_scale_factor = True
  
      # interpolate利用插值的方法缩放图片
      # image[None]操作是在最前面添加batch维度[C, H, W] -> [1, C, H, W]
      # bilinear只支持4D Tensor
      image = torch.nn.functional.interpolate(
          image[None],
          size=size,
          scale_factor=scale_factor,
          mode="bilinear",
          recompute_scale_factor=recompute_scale_factor,
          align_corners=False,
      )[0]
  
      if target is None:
          return image, target
  
      if "masks" in target:
          mask = target["masks"]
          mask = torch.nn.functional.interpolate(
              mask[:, None].float(),
              size=size,
              scale_factor=scale_factor,
              recompute_scale_factor=recompute_scale_factor,
          )[
              :, 0
          ].byte()  # self.byte() is equivalent to self.to(torch.uint8).
          target["masks"] = mask
  
      return image, target
  
imports: import math
  from typing import List, Tuple, Dict, Optional
  import torch
  from torch import nn, Tensor
  import torch.nn.functional
  import torchvision
  from .image_list import ImageList
label_desc: Use image node_id 5 for calling a global function with example usage: _resize_image_and_masks(image, _min_size, _max_size, target, fixed_size) and returns: image,  target, image,  target