class_docstr: Container for performing patch-level image data augmentation.
  
  .. image:: _static/img/PatchSequential.png
  
  PatchSequential breaks input images into patches by a given grid size, which will be resembled back
  afterwards.
  
  Different image processing and augmentation methods will be performed on each patch region as
  in :cite:`lin2021patch`.
  
  Args:
      *args: a list of processing modules.
      grid_size: controls the grid board separation.
      padding: same or valid padding. If same padding, it will pad to include all pixels if the input
          tensor cannot be divisible by grid_size. If valid padding, the redundant border will be removed.
      same_on_batch: apply the same transformation across the batch.
          If None, it will not overwrite the function-wise settings.
      keepdim: whether to keep the output shape the same as input (True) or broadcast it
          to the batch form (False). If None, it will not overwrite the function-wise settings.
      patchwise_apply: apply image processing args will be applied patch-wisely.
          if ``True``, the number of args must be equal to grid number.
          if ``False``, the image processing args will be applied as a sequence to all patches.
      random_apply: randomly select a sublist (order agnostic) of args to
          apply transformation.
          If ``int`` (batchwise mode only), a fixed number of transformations will be selected.
          If ``(a,)`` (batchwise mode only), x number of transformations (a <= x <= len(args)) will be selected.
          If ``(a, b)`` (batchwise mode only), x number of transformations (a <= x <= b) will be selected.
          If ``True``, the whole list of args will be processed in a random order.
          If ``False`` and not ``patchwise_apply``, the whole list of args will be processed in original order.
          If ``False`` and ``patchwise_apply``, the whole list of args will be processed in original order
          location-wisely.
  
  .. note::
      Transformation matrix returned only considers the transformation applied in ``kornia.augmentation`` module.
      Those transformations in ``kornia.geometry`` will not be taken into account.
  
  .. note::
      See a working example `here <https://kornia.github.io/tutorials/nbs/data_patch_sequential.html>`__.
  
  Examples:
      >>> import kornia.augmentation as K
      >>> input = torch.randn(2, 3, 224, 224)
      >>> seq = PatchSequential(
      ...     ImageSequential(
      ...         K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=0.5),
      ...         K.RandomPerspective(0.2, p=0.5),
      ...         K.RandomSolarize(0.1, 0.1, p=0.5),
      ...     ),
      ...     K.RandomAffine(360, p=1.0),
      ...     ImageSequential(
      ...         K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=0.5),
      ...         K.RandomPerspective(0.2, p=0.5),
      ...         K.RandomSolarize(0.1, 0.1, p=0.5),
      ...     ),
      ...     K.RandomSolarize(0.1, 0.1, p=0.1),
      ...     grid_size=(2,2),
      ...     patchwise_apply=True,
      ...     same_on_batch=True,
      ...     random_apply=False,
      ... )
      >>> out = seq(input)
      >>> out.shape
      torch.Size([2, 3, 224, 224])
      >>> out1 = seq(input, params=seq._params)
      >>> torch.equal(out, out1)
      True
  
  Perform ``OneOf`` transformation with ``random_apply=1`` and ``random_apply_weights`` in ``PatchSequential``.
  
      >>> import kornia
      >>> input = torch.randn(2, 3, 224, 224)
      >>> seq = PatchSequential(
      ...     ImageSequential(
      ...         K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=0.5),
      ...         K.RandomPerspective(0.2, p=0.5),
      ...         K.RandomSolarize(0.1, 0.1, p=0.5),
      ...     ),
      ...     K.RandomAffine(360, p=1.0),
      ...     K.RandomSolarize(0.1, 0.1, p=0.1),
      ...     grid_size=(2,2),
      ...     patchwise_apply=False,
      ...     random_apply=1,
      ...     random_apply_weights=[0.5, 0.3, 0.8]
      ... )
      >>> out = seq(input)
      >>> out.shape
      torch.Size([2, 3, 224, 224])
class_docstr_tok: ["Container","for","performing","patch-level","image","data","augmentation",".","..","image",":",":","_static\/img\/PatchSequential.png","PatchSequential","breaks","input","images","into","patches","by","a","given","grid","size",",","which","will","be","resembled","back","afterwards",".","Different","image","processing","and","augmentation","methods","will","be","performed","on","each","patch","region","as","in",":","cite",":","`","lin2021patch","`",".","Args",":","*","args",":","a","list","of","processing","modules",".","grid_size",":","controls","the","grid","board","separation",".","padding",":","same","or","valid","padding",".","If","same","padding",",","it","will","pad","to","include","all","pixels","if","the","input","tensor","can","not","be","divisible","by","grid_size",".","If","valid","padding",",","the","redundant","border","will","be","removed",".","same_on_batch",":","apply","the","same","transformation","across","the","batch",".","If","None",",","it","will","not","overwrite","the","function-wise","settings",".","keepdim",":","whether","to","keep","the","output","shape","the","same","as","input","(","True",")","or","broadcast","it","to","the","batch","form","(","False",")",".","If","None",",","it","will","not","overwrite","the","function-wise","settings",".","patchwise_apply",":","apply","image","processing","args","will","be","applied","patch-wisely",".","if","``","True","``",",","the","number","of","args","must","be","equal","to","grid","number",".","if","``","False","``",",","the","image","processing","args","will","be","applied","as","a","sequence","to","all","patches",".","random_apply",":","randomly","select","a","sublist","(","order","agnostic",")","of","args","to","apply","transformation",".","If","``","int","``","(","batchwise","mode","only",")",",","a","fixed","number","of","transformations","will","be","selected",".","If","``","(","a",",",")","``","(","batchwise","mode","only",")",",","x","number","of","transformations","(","a","<","=","x","<","=","len","(","args",")",")","will","be","selected",".","If","``","(","a",",","b",")","``","(","batchwise","mode","only",")",",","x","number","of","transformations","(","a","<","=","x","<","=","b",")","will","be","selected",".","If","``","True","``",",","the","whole","list","of","args","will","be","processed","in","a","random","order",".","If","``","False","``","and","not","``","patchwise_apply","``",",","the","whole","list","of","args","will","be","processed","in","original","order",".","If","``","False","``","and","``","patchwise_apply","``",",","the","whole","list","of","args","will","be","processed","in","original","order","location-wisely",".","..","note",":",":","Transformation","matrix","returned","only","considers","the","transformation","applied","in","``","kornia.augmentation","``","module",".","Those","transformations","in","``","kornia.geometry","``","will","not","be","taken","into","account",".","..","note",":",":","See","a","working","example","`","here","<","https",":","\/\/kornia.github.io\/tutorials\/nbs\/data_patch_sequential.html",">","`","__",".","Examples",":",">",">",">","import","kornia.augmentation","as","K",">",">",">","input","=","torch.randn","(","2",",","3",",","224",",","224",")",">",">",">","seq","=","PatchSequential","(","...","ImageSequential","(","...","K.ColorJiggle","(","0.1",",","0.1",",","0.1",",","0.1",",","p=0.5",")",",","...","K.RandomPerspective","(","0.2",",","p=0.5",")",",","...","K.RandomSolarize","(","0.1",",","0.1",",","p=0.5",")",",","...",")",",","...","K.RandomAffine","(","360",",","p=1.0",")",",","...","ImageSequential","(","...","K.ColorJiggle","(","0.1",",","0.1",",","0.1",",","0.1",",","p=0.5",")",",","...","K.RandomPerspective","(","0.2",",","p=0.5",")",",","...","K.RandomSolarize","(","0.1",",","0.1",",","p=0.5",")",",","...",")",",","...","K.RandomSolarize","(","0.1",",","0.1",",","p=0.1",")",",","...","grid_size=","(","2,2",")",",","...","patchwise_apply=True",",","...","same_on_batch=True",",","...","random_apply=False",",","...",")",">",">",">","out","=","seq","(","input",")",">",">",">","out.shape","torch.Size","(","[","2",",","3",",","224",",","224","]",")",">",">",">","out1","=","seq","(","input",",","params=seq._params",")",">",">",">","torch.equal","(","out",",","out1",")","True","Perform","``","OneOf","``","transformation","with","``","random_apply=1","``","and","``","random_apply_weights","``","in","``","PatchSequential","``",".",">",">",">","import","kornia",">",">",">","input","=","torch.randn","(","2",",","3",",","224",",","224",")",">",">",">","seq","=","PatchSequential","(","...","ImageSequential","(","...","K.ColorJiggle","(","0.1",",","0.1",",","0.1",",","0.1",",","p=0.5",")",",","...","K.RandomPerspective","(","0.2",",","p=0.5",")",",","...","K.RandomSolarize","(","0.1",",","0.1",",","p=0.5",")",",","...",")",",","...","K.RandomAffine","(","360",",","p=1.0",")",",","...","K.RandomSolarize","(","0.1",",","0.1",",","p=0.1",")",",","...","grid_size=","(","2,2",")",",","...","patchwise_apply=False",",","...","random_apply=1",",","...","random_apply_weights=","[","0.5",",","0.3",",","0.8","]","...",")",">",">",">","out","=","seq","(","input",")",">",">",">","out.shape","torch.Size","(","[","2",",","3",",","224",",","224","]",")"]
code: def __init__(
      self,
      *args: Module,
      grid_size: Tuple[int, int] = (4, 4),
      padding: str = "same",
      same_on_batch: Optional[bool] = None,
      keepdim: Optional[bool] = None,
      patchwise_apply: bool = True,
      random_apply: Union[int, bool, Tuple[int, int]] = False,
      random_apply_weights: Optional[List[float]] = None,
  ) -> None:
      _random_apply: Optional[Union[int, Tuple[int, int]]]
  
      if patchwise_apply and random_apply is True:
          # will only apply [1, 4] augmentations per patch
          _random_apply = (1, 4)
      elif patchwise_apply and random_apply is False:
          if len(args) != grid_size[0] * grid_size[1]:
              raise ValueError(
                  "The number of processing modules must be equal with grid size."
                  f"Got {len(args)} and {grid_size[0] * grid_size[1]}. "
                  "Please set random_apply = True or patchwise_apply = False."
              )
          _random_apply = random_apply
      elif patchwise_apply and isinstance(random_apply, (int, tuple)):
          raise ValueError(
              f"Only boolean value allowed when `patchwise_apply` is set to True. Got {random_apply}."
          )
      else:
          _random_apply = random_apply
      super().__init__(
          *args,
          same_on_batch=same_on_batch,
          keepdim=keepdim,
          random_apply=_random_apply,
          random_apply_weights=random_apply_weights,
      )
      if padding not in ("same", "valid"):
          raise ValueError(
              f"`padding` must be either `same` or `valid`. Got {padding}."
          )
      self.grid_size = grid_size
      self.padding = padding
      self.patchwise_apply = patchwise_apply
      self._params: Optional[List[PatchParamItem]]
  
imports: from itertools import cycle, islice
  from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
  import torch
  import kornia.augmentation
  from kornia.augmentation.base import _AugmentationBase
  from kornia.contrib.extract_patches import extract_tensor_patches
  from kornia.core import Module, Tensor, concatenate
  from kornia.core import pad
  from kornia.geometry.boxes import Boxes
  from kornia.geometry.keypoints import Keypoints
  from .base import SequentialBase
  from .image import ImageSequential
  from .ops import InputSequentialOps
  from .params import ParamItem, PatchParamItem
label_desc: Use image node_id 1 to create a new PatchSequential object from inherited base classes: ImageSequential with example: obj = PatchSequential()