class_docstr: Crop random patches of a tensor image on a given size.
  
  .. image:: _static/img/RandomCrop.png
  
  Args:
      size: Desired output size (out_h, out_w) of the crop.
          Must be Tuple[int, int], then out_h = size[0], out_w = size[1].
      padding: Optional padding on each border
          of the image. Default is None, i.e no padding. If a sequence of length
          4 is provided, it is used to pad left, top, right, bottom borders
          respectively. If a sequence of length 2 is provided, it is used to
          pad left/right, top/bottom borders, respectively.
      pad_if_needed: It will pad the image if smaller than the
          desired size to avoid raising an exception. Since cropping is done
          after padding, the padding seems to be done at a random offset.
      fill: Pixel fill value for constant fill. Default is 0. If a tuple of
          length 3, it is used to fill R, G, B channels respectively.
          This value is only used when the padding_mode is constant.
      padding_mode: Type of padding. Should be: constant, reflect, replicate.
      resample: the interpolation mode.
      same_on_batch: apply the same transformation across the batch.
      align_corners: interpolation flag.
      p: probability of applying the transformation for the whole batch.
      keepdim: whether to keep the output shape the same as input (True) or broadcast it
               to the batch form (False).
      cropping_mode: The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
                     on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
                     to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
                     differentiability.
  
  Shape:
      - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
      - Output: :math:`(B, C, out_h, out_w)`
  
  Note:
      Input tensor must be float and normalized into [0, 1] for the best differentiability support.
      Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
      applied transformation will be merged int to the input transformation tensor and returned.
  
  Examples:
      >>> import torch
      >>> _ = torch.manual_seed(0)
      >>> inputs = torch.arange(1*1*3*3.).view(1, 1, 3, 3)
      >>> aug = RandomCrop((2, 2), p=1., cropping_mode="resample")
      >>> out = aug(inputs)
      >>> out
      tensor([[[[3., 4.],
                [6., 7.]]]])
      >>> aug.inverse(out, padding_mode="replicate")
      tensor([[[[3., 4., 4.],
                [3., 4., 4.],
                [6., 7., 7.]]]])
  
  To apply the exact augmenation again, you may take the advantage of the previous parameter state:
      >>> input = torch.randn(1, 3, 32, 32)
      >>> aug = RandomCrop((2, 2), p=1., cropping_mode="resample")
      >>> (aug(input) == aug(input, params=aug._params)).all()
      tensor(True)
code: def __init__(
      self,
      size: Tuple[int, int],
      padding: Optional[
          Union[int, Tuple[int, int], Tuple[int, int, int, int]]
      ] = None,
      pad_if_needed: Optional[bool] = False,
      fill: int = 0,
      padding_mode: str = "constant",
      resample: Union[str, int, Resample] = Resample.BILINEAR.name,
      same_on_batch: bool = False,
      align_corners: bool = True,
      p: float = 1.0,
      keepdim: bool = False,
      cropping_mode: str = "slice",
  ) -> None:
      # Since PyTorch does not support ragged tensor. So cropping function happens batch-wisely.
      super().__init__(
          p=1.0, same_on_batch=same_on_batch, p_batch=p, keepdim=keepdim
      )
      self._param_generator = rg.CropGenerator(size)
      self.flags = {
          "size": size,
          "padding": padding,
          "pad_if_needed": pad_if_needed,
          "fill": fill,
          "padding_mode": padding_mode,
          "resample": Resample.get(resample),
          "align_corners": align_corners,
          "cropping_mode": cropping_mode,
      }
  
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from kornia.augmentation import random_generator
  from kornia.augmentation._2d.geometric.base import GeometricAugmentationBase2D
  from kornia.constants import Resample
  from kornia.core import Tensor, pad, tensor
  from kornia.geometry.boxes import Boxes
  from kornia.geometry.keypoints import Keypoints
  from kornia.geometry.transform import crop_by_indices, crop_by_transform_mat, get_perspective_transform
label_desc: Use image node_id 1 to create a new RandomCrop object from inherited base classes: GeometricAugmentationBase2D with example: obj = RandomCrop(size, padding, pad_if_needed, fill, padding_mode, resample, same_on_batch, align_corners, p, keepdim, cropping_mode)