code: def clip_boxes_to_image(
      boxes: Tensor, size: Tuple[int, int]
  ) -> Tensor:
      """
      Clip boxes so that they lie inside an image of size ``size``.
  
      .. note::
          For clipping a :class:`~torchvision.tv_tensors.BoundingBoxes` object, consider using
          the transform :func:`~torchvision.transforms.v2.ClampBoundingBoxes` instead.
  
      Args:
          boxes (Tensor[N, 4]): boxes in ``(x1, y1, x2, y2)`` format
              with ``0 <= x1 < x2`` and ``0 <= y1 < y2``.
          size (Tuple[height, width]): size of the image
  
      Returns:
          Tensor[N, 4]: clipped boxes
      """
      if not torch.jit.is_scripting() and not torch.jit.is_tracing():
          _log_api_usage_once(clip_boxes_to_image)
      dim = boxes.dim()
      boxes_x = boxes[..., 0::2]
      boxes_y = boxes[..., 1::2]
      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)
          boxes_y = boxes_y.clamp(min=0, max=height)
  
      clipped_boxes = torch.stack((boxes_x, boxes_y), dim=dim)
      return clipped_boxes.reshape(boxes.shape)
  
imports: from typing import Tuple
  import torch
  import torchvision
  from torch import Tensor
  from torchvision.extension import _assert_has_ops
  from ..utils import _log_api_usage_once
  from ._box_convert import _box_cxcywh_to_xyxy, _box_xywh_to_xyxy, _box_xyxy_to_cxcywh, _box_xyxy_to_xywh
  from ._utils import _upcast
label_desc: Use image node_id 6 for calling a global function with example usage: clip_boxes_to_image(boxes, size) and returns: clipped_boxes