class_docstr: 2D boxes containing N or BxN boxes.
  
  Args:
      boxes: 2D boxes, shape of :math:`(N, 4, 2)`, :math:`(B, N, 4, 2)` or a list of :math:`(N, 4, 2)`.
          See below for more details.
      raise_if_not_floating_point: flag to control floating point casting behaviour when `boxes` is not a
          floating point tensor. True to raise an error when `boxes` isn't a floating point tensor, False
          to cast to float.
      mode: the box format of the input boxes.
  
  Note:
      **2D boxes format** is defined as a floating data type tensor of shape ``Nx4x2`` or ``BxNx4x2``
      where each box is a `quadrilateral <https://en.wikipedia.org/wiki/Quadrilateral>`_ defined by it's
      4 vertices coordinates (A, B, C, D). Coordinates must be in ``x, y`` order. The height and width of
      a box is defined as ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``. Examples of
      `quadrilaterals <https://en.wikipedia.org/wiki/Quadrilateral>`_ are rectangles, rhombus and trapezoids.
class_docstr_tok: ["2D","boxes","containing","N","or","BxN","boxes",".","Args",":","boxes",":","2D","boxes",",","shape","of",":","math",":","`","(","N",",","4",",","2",")","`",",",":","math",":","`","(","B",",","N",",","4",",","2",")","`","or","a","list","of",":","math",":","`","(","N",",","4",",","2",")","`",".","See","below","for","more","details",".","raise_if_not_floating_point",":","flag","to","control","floating","point","casting","behaviour","when","`","boxes","`","is","not","a","floating","point","tensor",".","True","to","raise","an","error","when","`","boxes","`","is","n't","a","floating","point","tensor",",","False","to","cast","to","float",".","mode",":","the","box","format","of","the","input","boxes",".","Note",":","*","*","2D","boxes","format","*","*","is","defined","as","a","floating","data","type","tensor","of","shape","``","Nx4x2","``","or","``","BxNx4x2","``","where","each","box","is","a","`","quadrilateral","<","https",":","\/\/en.wikipedia.org\/wiki\/Quadrilateral",">","`","_","defined","by","it's","4","vertices","coordinates","(","A",",","B",",","C",",","D",")",".","Coordinates","must","be","in","``","x",",","y","``","order",".","The","height","and","width","of","a","box","is","defined","as","``","width","=","xmax","-","xmin","+","1","``","and","``","height","=","ymax","-","ymin","+","1","``",".","Examples","of","`","quadrilaterals","<","https",":","\/\/en.wikipedia.org\/wiki\/Quadrilateral",">","`","_","are","rectangles",",","rhombus","and","trapezoids","."]
docstr: Cast :class:`Boxes` to a tensor. ``mode`` controls which 2D boxes format should be use to represent
  boxes in the tensor.
  
  Args:
      mode: the output box format. It could be:
  
          * 'xyxy': boxes are defined as ``xmin, ymin, xmax, ymax`` where ``width = xmax - xmin`` and
            ``height = ymax - ymin``.
          * 'xyxy_plus': similar to 'xyxy' mode but where box width and length are defined as
            ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``.
          * 'xywh': boxes are defined as ``xmin, ymin, width, height`` where ``width = xmax - xmin``
            and ``height = ymax - ymin``.
          * 'vertices': boxes are defined by their vertices points in the following ``clockwise`` order:
            *top-left, top-right, bottom-right, bottom-left*. Vertices coordinates are in (x,y) order. Finally,
            box width and height are defined as ``width = xmax - xmin`` and ``height = ymax - ymin``.
          * 'vertices_plus': similar to 'vertices' mode but where box width and length are defined as
            ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``. ymin + 1``.
      as_padded_sequence: whether to keep the pads for a list of boxes. This parameter is only valid
          if the boxes are from a box list whilst `from_tensor`.
  
  Returns:
      Boxes tensor in the ``mode`` format. The shape depends with the ``mode`` value:
  
          * 'vertices' or 'verticies_plus': :math:`(N, 4, 2)` or :math:`(B, N, 4, 2)`.
          * Any other value: :math:`(N, 4)` or :math:`(B, N, 4)`.
  
  Examples:
      >>> boxes_xyxy = torch.as_tensor([[0, 3, 1, 4], [5, 1, 8, 4]])
      >>> boxes = Boxes.from_tensor(boxes_xyxy)
      >>> assert (boxes_xyxy == boxes.to_tensor(mode='xyxy')).all()
code: def to_tensor(
      self, mode: Optional[str] = None, as_padded_sequence: bool = False
  ) -> torch.Tensor | list[torch.Tensor]:
      r"""Cast :class:`Boxes` to a tensor. ``mode`` controls which 2D boxes format should be use to represent
      boxes in the tensor.
  
      Args:
          mode: the output box format. It could be:
  
              * 'xyxy': boxes are defined as ``xmin, ymin, xmax, ymax`` where ``width = xmax - xmin`` and
                ``height = ymax - ymin``.
              * 'xyxy_plus': similar to 'xyxy' mode but where box width and length are defined as
                ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``.
              * 'xywh': boxes are defined as ``xmin, ymin, width, height`` where ``width = xmax - xmin``
                and ``height = ymax - ymin``.
              * 'vertices': boxes are defined by their vertices points in the following ``clockwise`` order:
                *top-left, top-right, bottom-right, bottom-left*. Vertices coordinates are in (x,y) order. Finally,
                box width and height are defined as ``width = xmax - xmin`` and ``height = ymax - ymin``.
              * 'vertices_plus': similar to 'vertices' mode but where box width and length are defined as
                ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``. ymin + 1``.
          as_padded_sequence: whether to keep the pads for a list of boxes. This parameter is only valid
              if the boxes are from a box list whilst `from_tensor`.
  
      Returns:
          Boxes tensor in the ``mode`` format. The shape depends with the ``mode`` value:
  
              * 'vertices' or 'verticies_plus': :math:`(N, 4, 2)` or :math:`(B, N, 4, 2)`.
              * Any other value: :math:`(N, 4)` or :math:`(B, N, 4)`.
  
      Examples:
          >>> boxes_xyxy = torch.as_tensor([[0, 3, 1, 4], [5, 1, 8, 4]])
          >>> boxes = Boxes.from_tensor(boxes_xyxy)
          >>> assert (boxes_xyxy == boxes.to_tensor(mode='xyxy')).all()
      """
      batched_boxes = (
          self._data if self._is_batched else self._data.unsqueeze(0)
      )
  
      boxes: torch.Tensor | list[torch.Tensor]
  
      # Create boxes in xyxy_plus format.
      boxes = torch.stack(
          [batched_boxes.amin(dim=-2), batched_boxes.amax(dim=-2)],
          dim=-2,
      ).view(batched_boxes.shape[0], batched_boxes.shape[1], 4)
  
      if mode is None:
          mode = self.mode
  
      mode = mode.lower()
  
      if mode in ("xyxy", "xyxy_plus"):
          pass
      elif mode in ("xywh", "vertices", "vertices_plus"):
          height, width = (
              boxes[..., 3] - boxes[..., 1] + 1,
              boxes[..., 2] - boxes[..., 0] + 1,
          )
          boxes[..., 2] = width
          boxes[..., 3] = height
      else:
          raise ValueError(f"Unknown mode {mode}")
  
      if mode in ("xyxy", "vertices"):
          offset = torch.as_tensor(
              [0, 0, 1, 1], device=boxes.device, dtype=boxes.dtype
          )
          boxes = boxes + offset
  
      if mode.startswith("vertices"):
          boxes = _boxes_to_polygons(
              boxes[..., 0], boxes[..., 1], boxes[..., 2], boxes[..., 3]
          )
  
      if self._N is not None and not as_padded_sequence:
          boxes = [
              torch.nn.functional.pad(
                  o, (len(o.shape) - 1) * [0, 0] + [0, -n]
              )
              for o, n in zip(boxes, self._N)
          ]
      else:
          boxes = boxes if self._is_batched else boxes.squeeze(0)
      return boxes
  
imports: from __future__ import annotations
  from typing import Optional, cast
  import torch
  from torch import Size
  from kornia.core import Tensor, stack, zeros
  from kornia.geometry.bbox import validate_bbox
  from kornia.geometry.linalg import transform_points
  from kornia.utils import eye_like
label_desc: Use image node_id 15 for calling the Boxes obj's underlying member method code with example usage: obj.to_tensor(mode, as_padded_sequence) and returns: boxes