code: def crop_and_resize(
      input_tensor: Tensor,
      boxes: Tensor,
      size: Tuple[int, int],
      mode: str = "bilinear",
      padding_mode: str = "zeros",
      align_corners: bool = True,
  ) -> Tensor:
      r"""Extract crops from 2D images (4D tensor) and resize given a bounding box.
  
      Args:
          input_tensor: the 2D image tensor with shape (B, C, H, W).
          boxes : a tensor containing the coordinates of the bounding boxes to be extracted.
              The tensor must have the shape of Bx4x2, where each box is defined in the following (clockwise)
              order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in the x, y order.
              The coordinates would compose a rectangle with a shape of (N1, N2).
          size: a tuple with the height and width that will be
              used to resize the extracted patches.
          mode: interpolation mode to calculate output values
            ``'bilinear'`` | ``'nearest'``.
          padding_mode: padding mode for outside grid values
            ``'zeros'`` | ``'border'`` | 'reflection'.
          align_corners: mode for grid_generation.
  
      Returns:
          Tensor: tensor containing the patches with shape BxCxN1xN2.
  
      Example:
          >>> input = torch.tensor([[[
          ...     [1., 2., 3., 4.],
          ...     [5., 6., 7., 8.],
          ...     [9., 10., 11., 12.],
          ...     [13., 14., 15., 16.],
          ... ]]])
          >>> boxes = torch.tensor([[
          ...     [1., 1.],
          ...     [2., 1.],
          ...     [2., 2.],
          ...     [1., 2.],
          ... ]])  # 1x4x2
          >>> crop_and_resize(input, boxes, (2, 2), mode='nearest', align_corners=True)
          tensor([[[[ 6.,  7.],
                    [10., 11.]]]])
      """
      if not isinstance(input_tensor, Tensor):
          raise TypeError(
              f"Input tensor type is not a Tensor. Got {type(input_tensor)}"
          )
  
      if not isinstance(boxes, Tensor):
          raise TypeError(
              f"Input boxes type is not a Tensor. Got {type(boxes)}"
          )
  
      if not isinstance(size, (tuple, list)) and len(size) == 2:
          raise ValueError(
              f"Input size must be a tuple/list of length 2. Got {size}"
          )
  
      if len(input_tensor.shape) != 4:
          raise AssertionError(
              f"Only tensor with shape (B, C, H, W) supported. Got {input_tensor.shape}."
          )
  
      # unpack input data
      dst_h, dst_w = size
  
      # [x, y] origin
      # top-left, top-right, bottom-right, bottom-left
      points_src = boxes.to(input_tensor)
  
      # [x, y] destination
      # top-left, top-right, bottom-right, bottom-left
      points_dst = tensor(
          [
              [
                  [0, 0],
                  [dst_w - 1, 0],
                  [dst_w - 1, dst_h - 1],
                  [0, dst_h - 1],
              ]
          ],
          device=input_tensor.device,
          dtype=input_tensor.dtype,
      ).expand(points_src.shape[0], -1, -1)
  
      return crop_by_boxes(
          input_tensor,
          points_src,
          points_dst,
          mode,
          padding_mode,
          align_corners,
      )
  
file_path: kornia/kornia/geometry/transform/crop2d.py
imports: from typing import Optional, Tuple
  import torch
  from kornia.core import Tensor, as_tensor, pad, tensor
  from kornia.geometry.bbox import infer_bbox_shape, validate_bbox
  from .affwarp import resize
  from .imgwarp import get_perspective_transform, warp_affine
label_desc: Use image node_id 1 for calling a global function with example usage: crop_and_resize(input_tensor, boxes, size, mode, padding_mode, align_corners) and returns: crop_by_boxes