code: def clip_boxes_to_image(boxes, size):
      # type: (Tensor, Tuple[int, int]) -> Tensor
      """
      Clip boxes so that they lie inside an image of size `size`.
      裁剪预测的boxes信息，将越界的坐标调整到图片边界上
  
      Arguments:
          boxes (Tensor[N, 4]): boxes in (x1, y1, x2, y2) format
          size (Tuple[height, width]): size of the image
  
      Returns:
          clipped_boxes (Tensor[N, 4])
      """
      dim = boxes.dim()
      boxes_x = boxes[..., 0::2]  # x1, x2
      boxes_y = boxes[..., 1::2]  # y1, y2
      height, width = size
  
      if torchvision._is_tracing():
          boxes_x = torch.max(
              boxes_x,
              torch.tensor(0, dtype=boxes.dtype, device=boxes.device),
          )
          boxes_x = torch.min(
              boxes_x,
              torch.tensor(
                  width, dtype=boxes.dtype, device=boxes.device
              ),
          )
          boxes_y = torch.max(
              boxes_y,
              torch.tensor(0, dtype=boxes.dtype, device=boxes.device),
          )
          boxes_y = torch.min(
              boxes_y,
              torch.tensor(
                  height, dtype=boxes.dtype, device=boxes.device
              ),
          )
      else:
          boxes_x = boxes_x.clamp(
              min=0, max=width
          )  # 限制x坐标范围在[0,width]之间
          boxes_y = boxes_y.clamp(
              min=0, max=height
          )  # 限制y坐标范围在[0,height]之间
  
      clipped_boxes = torch.stack((boxes_x, boxes_y), dim=dim)
      return clipped_boxes.reshape(boxes.shape)
  
file_path: deep-learning-for-image-processing/pytorch_object_detection/faster_rcnn/network_files/boxes.py
imports: import torch
  from typing import Tuple
  from torch import Tensor
  import torchvision
label_desc: Use image node_id 4 for calling a global function with example usage: clip_boxes_to_image(boxes, size) and returns: clipped_boxes