code: def _resize_image(image, self_min_size, self_max_size):
      # type: (Tensor, float, float) -> Tensor
      im_shape = torch.tensor(image.shape[-2:])
      min_size = float(torch.min(im_shape))  # 获取高宽中的最小值
      max_size = float(torch.max(im_shape))  # 获取高宽中的最大值
      scale_factor = self_min_size / min_size  # 根据指定最小边长和图片最小边长计算缩放比例
  
      # 如果使用该缩放比例计算的图片最大边长大于指定的最大边长
      if max_size * scale_factor > self_max_size:
          scale_factor = (
              self_max_size / max_size
          )  # 将缩放比例设为指定最大边长和图片最大边长之比
  
      # interpolate利用插值的方法缩放图片
      # image[None]操作是在最前面添加batch维度[C, H, W] -> [1, C, H, W]
      # bilinear只支持4D Tensor
      image = torch.nn.functional.interpolate(
          image[None],
          scale_factor=scale_factor,
          mode="bilinear",
          recompute_scale_factor=True,
          align_corners=False,
      )[0]
  
      return image
  
imports: import math
  from typing import List, Tuple, Dict, Optional
  import torch
  from torch import nn, Tensor
  import torchvision
  from .image_list import ImageList
label_desc: Use image node_id 2 for calling a global function with example usage: _resize_image(image, _min_size, _max_size) and returns: image