
    ёiE                   J   % S SK Jr  S SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
JrJrJrJrJrJr  S SKrS SKJr  S SKrSSKJr  \
(       a5  S SKJ	r  S SKJr  S S	KJr  S S
KJ r J!r!J"r"J#r#  \\S      r$S\%S'   SSKJ&r&J'r'J(r(  \" SSSSSS9r)\" SSSSSS9r* " S S\\\)\*4   5      r+/ r,S r-SS \." S5      4S4S jr/ " S S\+\)\*4   5      r0 " S S\+\)\*4   5      r1 " S  S!\1\)S4   5      r2 " S" S#\1\)\*4   5      r3 " S$ S%\1\)\*4   5      r4 " S& S'\1\)\*4   5      r5 " S( S)\1\)\*4   5      r6 " S* S+\1\)\*4   5      r7 " S, S-\1\)\*4   5      r8 " S. S/\1\)\*4   5      r9 " S0 S1\1\)\*4   5      r: " S2 S3\1\)\*4   5      r; " S4 S5\1\)\*4   5      r< " S6 S7\1\)\*4   5      r= " S8 S9\1\)\*4   5      r> " S: S;\1\)\*4   5      r? " S< S=\1\)\*4   5      r@S> rASJS? jrB " S@ SA\1\)\*4   5      rC " SB SC\1\)\*4   5      rD " SD SE\1\)\*4   5      rE " SF SG\1\)\*4   5      rF " SH SI\1\)\*4   5      rGg)K    )annotationsN)IterableSequence)TYPE_CHECKINGAnyGenericLiteralProtocolTypeVaroverload)	TypeAlias   )
functional)Image)Tensor)DataLayoutImageSize2Size3Size4)imagecoordsboxesmaskr   _TransformInputKeys)_InterpolationCv2_InterpolationPil_PaddingMode_InputTr   PILImageznpt.NDArray[Any]T)contravariant_RetT)	covariantc                  F    \ rS rSr\SS j5       r\SS j5       rS	S jrSrg)

_Transform?   c                    g N selfdatas     c/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/vision/transforms/transforms.py__call___Transform.__call__@       03    c                    g r'   r(   r)   s     r,   r-   r.   C       HKr0   c                    g r'   r(   r)   s     r,   r-   r.   F   s    Sr0   r(   Nr+   r   returnr!   r+   tuple[_InputT, ...]r5   tuple[_RetT, ...]r5   r   )__name__
__module____qualname____firstlineno__r   r-   __static_attributes__r(   r0   r,   r$   r$   ?   s!    3 3K K(r0   r$   c                   [         R                  " U 5      (       a  U R                  $ [         R                  " U 5      (       a  U R                  S S S S S2   $ [         R
                  " U 5      (       a}  [        U R                  5      S:X  a  U R                  SS  S S S2   $ [        U R                  5      S:X  a  U R                  SS  S S S2   $ [        S[        U R                  5       35      e[        S[        U 5       35      e)N      r      z<The dim for input Tensor should be 3-D or 4-D, but received zUnexpected type )
F_is_pil_imagesize_is_numpy_imageshape_is_tensor_imagelen
ValueError	TypeErrortypeimgs    r,   _get_image_sizerP   L   s    sxx	
		3		yy!}TrT""	
		C	 	 syy>Q99QR=2&&^q 99QR=2&&NsSVS\S\~N^_  *49+677r0   infc                   [        U [        R                  5      (       a7  U S:  a  [        SU S35      eX -
  X -   /n U(       a  [	        U S   S5      U S'   Ok[        U [
        [        45      (       aB  [        U 5      S:X  a3  US   U S   s=::  a  U S   s=::  a	  US   ::  d  O  [        U SU 35      eO[        U S35      eU S   U S   s=:X  a  U:X  a  O  U $ S n U $ )Nr   If z- is a single number, it must be non negative.r@   r   z values should be between z9 should be a single number or a list/tuple with length 2.)	
isinstancenumbersNumberrK   maxtuplelistrJ   rL   )valuenamecenterboundclip_first_on_zeros        r,   _check_inputr_   ^   s     %((19dVHI  058Q'E!H	EE4=	)	)c%jAoQx58;uQx;58;v%?wGHH < fMN
 	
 Qx58%v%L Lr0   c                  j    \ rS rSr% SrS\S'   SS jr\SS j5       r\SS j5       rSS jrSS	 jr	S
r
g)Composev   a)  
Composes several transforms together use for composing list of transforms
together for a dataset transform.

Args:
    transforms (list|tuple): List/Tuple of transforms to compose.

Returns:
    A compose object which is callable, __call__ for this Compose
    object will call each given :attr:`transforms` sequently.

Examples:

    .. code-block:: python

        >>> from paddle.vision.datasets import Flowers
        >>> from paddle.vision.transforms import Compose, ColorJitter, Resize
        >>> transform = Compose([ColorJitter(), Resize(size=608)])
        >>> flowers = Flowers(mode='test', transform=transform)
        >>> for i in range(3):
        ...     sample = flowers[i]
        ...     print(sample[0].size, sample[1])
        (916, 608) [1]
        (758, 608) [1]
        (811, 608) [1]
Sequence[_Transform[Any, Any]]
transformsc                    Xl         g r'   rd   )r*   rd   s     r,   __init__Compose.__init__   s    $r0   c                    g r'   r(   r)   s     r,   r-   Compose.__call__   r/   r0   c                    g r'   r(   r)   s     r,   r-   rj      r2   r0   c           
         U R                    H  n U" U5      nM     U$ ! [         a0  n[        R                  " 5       n[	        SU SU SU 35        UeS nAff = f)Nzfail to perform transform [z] with error: z and stack:
)rd   	Exception	traceback
format_excprint)r*   r+   fe
stack_infos        r,   r-   rj      sm    Aw !   &113
1!Nczl4 s   
A+AAc                    U R                   R                  S-   nU R                   H  nUS-  nUSU 3-  nM     US-  nU$ )N(
z    z
))	__class__r:   rd   )r*   format_stringts      r,   __repr__Compose.__repr__   sP    //#5AT!MtA3Z'M ! 	r0   rf   N)rd   rc   r5   Noner4   r6   r9   )r5   str)r:   r;   r<   r=   __doc____annotations__rg   r   r-   rz   r>   r(   r0   r,   ra   ra   v   s<    6 /.% 3 3K Kr0   ra   c                      \ rS rSr% SrS\S'   S\S'   SSS jjrS	 r\SS
 j5       r	\SS j5       r	SS jr	S r
S rS rS rS rSrg)BaseTransform   a  
Base class of all transforms used in computer vision.

calling logic:

.. code-block:: text

    if keys is None:
        _get_params -> _apply_image()
    else:
        _get_params -> _apply_*() for * in keys

If you want to implement a self-defined transform method for image,
rewrite _apply_* method in subclass.

Args:
    keys (list[str]|tuple[str], optional): Input type. Input is a tuple contains different structures,
        key is used to specify the type of input. For example, if your input
        is image type, then the key can be None or ("image"). if your input
        is (image, image) type, then the keys should be ("image", "image").
        if your input is (image, boxes), then the keys should be ("image", "boxes").

        Current available strings & data type are describe below:

            - "image": input image, with shape of (H, W, C)
            - "coords": coordinates, with shape of (N, 2)
            - "boxes": bounding boxes, with shape of (N, 4), "xyxy" format,the 1st "xy" represents
              top left point of a box,the 2nd "xy" represents right bottom point.
            - "mask": map used for segmentation, with shape of (H, W, 1)

        You can also customize your data types only if you implement the corresponding
        _apply_*() methods, otherwise ``NotImplementedError`` will be raised.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> import paddle.vision.transforms.functional as F
        >>> from paddle.vision.transforms import BaseTransform

        >>> def _get_image_size(img):
        ...     if F._is_pil_image(img):
        ...         return img.size
        ...     elif F._is_numpy_image(img):
        ...         return img.shape[:2][::-1]
        ...     else:
        ...         raise TypeError("Unexpected type {}".format(type(img)))
        ...
        >>> class CustomRandomFlip(BaseTransform): # type: ignore[type-arg]
        ...     def __init__(self, prob=0.5, keys=None):
        ...         super().__init__(keys)
        ...         self.prob = prob
        ...
        ...     def _get_params(self, inputs):
        ...         image = inputs[self.keys.index('image')]
        ...         params = {}
        ...         params['flip'] = np.random.random() < self.prob
        ...         params['size'] = _get_image_size(image)
        ...         return params
        ...
        ...     def _apply_image(self, image):
        ...         if self.params['flip']:
        ...             return F.hflip(image)
        ...         return image
        ...
        ...     # if you only want to transform image, do not need to rewrite this function
        ...     def _apply_coords(self, coords):
        ...         if self.params['flip']:
        ...             w = self.params['size'][0]
        ...             coords[:, 0] = w - coords[:, 0]
        ...         return coords
        ...
        ...     # if you only want to transform image, do not need to rewrite this function
        ...     def _apply_boxes(self, boxes):
        ...         idxs = np.array([(0, 1), (2, 1), (0, 3), (2, 3)]).flatten()
        ...         coords = np.asarray(boxes).reshape(-1, 4)[:, idxs].reshape(-1, 2)
        ...         coords = self._apply_coords(coords).reshape((-1, 4, 2))
        ...         minxy = coords.min(axis=1)
        ...         maxxy = coords.max(axis=1)
        ...         trans_boxes = np.concatenate((minxy, maxxy), axis=1)
        ...         return trans_boxes
        ...
        ...     # if you only want to transform image, do not need to rewrite this function
        ...     def _apply_mask(self, mask):
        ...         if self.params['flip']:
        ...             return F.hflip(mask)
        ...         return mask
        ...
        >>> # create fake inputs
        >>> fake_img = Image.fromarray((np.random.rand(400, 500, 3) * 255.).astype('uint8'))
        >>> fake_boxes = np.array([[2, 3, 200, 300], [50, 60, 80, 100]])
        >>> fake_mask = fake_img.convert('L')
        >>> # only transform for image:
        >>> flip_transform = CustomRandomFlip(1.0)
        >>> converted_img = flip_transform(fake_img)
        >>> # transform for image, boxes and mask
        >>> flip_transform = CustomRandomFlip(1.0, keys=('image', 'boxes', 'mask'))
        >>> (converted_img, converted_boxes, converted_mask) = flip_transform((fake_img, fake_boxes, fake_mask))
        >>> converted_boxes
        array([[300,   3, 498, 300],
               [420,  60, 450, 100]])

r   keysr   paramsNc                    Uc  SnO#[        U[        5      (       d  [        SU 35      eU H#  nU R                  U5      b  M  [	        U S35      e   Xl        S U l        g )N)r   z(keys should be a sequence, but got keys=z is unsupported data structure)rT   r   rK   
_get_applyNotImplementedErrorr   r   )r*   r   ks      r,   rg   BaseTransform.__init__!  sh    <DD(++GvNOOAq!))QC/M*NOO  	 r0   c                    g r'   r(   r*   inputss     r,   _get_paramsBaseTransform._get_params.  s    r0   c                    g r'   r(   r   s     r,   r-   BaseTransform.__call__1  s    25r0   c                    g r'   r(   r   s     r,   r-   r   4  s    JMr0   c                H   [        U[        5      (       d  U4nU R                  U5      U l        / n[	        [        [        U5      [        U R                  5      5      5       HR  nU R                  U R                  U   5      nUc  UR                  X   5        M9  UR                  U" X   5      5        MT     [        U5      [        U R                  5      :  a'  UR                  U[        U R                  5      S 5        [        U5      S:X  a  US   nU$ [        U5      nU$ )z$Apply transform on single input dataNr   r   )rT   rX   r   r   rangeminrJ   r   r   appendextend)r*   r   outputsi
apply_funcs        r,   r-   r   7  s    &%((YF&&v.s3v;DII78A16J!vy)z&)45 9 v;TYY'NN6#dii."234w<1ajG  GnGr0   c                "    [        U SU 3S 5      $ )N_apply_)getattr)r*   keys     r,   r   BaseTransform._get_applyN  s    twse_d33r0   c                    [         er'   r   )r*   r   s     r,   _apply_imageBaseTransform._apply_imageQ      !!r0   c                    [         er'   r   )r*   r   s     r,   _apply_boxesBaseTransform._apply_boxesT  r   r0   c                    [         er'   r   )r*   r   s     r,   _apply_maskBaseTransform._apply_maskW  r   r0   c                    [         er'   r   )r*   r   s     r,   _apply_coordsBaseTransform._apply_coordsZ  r   r0   )r   r   r'   )r   _TransformInputKeys | Noner5   r|   )r   r   r5   r!   )r   r7   r5   r8   r9   )r:   r;   r<   r=   r~   r   rg   r   r   r-   r   r   r   r   r   r>   r(   r0   r,   r   r      s\    hT K 5 5M M.4""""r0   r   c                  T   ^  \ rS rSr% SrS\S'     S     S	U 4S jjjrS rSrU =r	$ )
ToTensori^  a  Convert a ``PIL.Image`` or ``numpy.ndarray`` to ``paddle.Tensor``.

Converts a PIL.Image or numpy.ndarray (H x W x C) to a paddle.Tensor of shape (C x H x W).

If input is a grayscale image (H x W), it will be converted to an image of shape (H x W x 1).
And the shape of output tensor will be (1 x H x W).

If you want to keep the shape of output tensor as (H x W x C), you can set data_format = ``HWC`` .

Converts a PIL.Image or numpy.ndarray in the range [0, 255] to a paddle.Tensor in the
range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr,
RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8.

In the other cases, tensors are returned without scaling.

Args:
    data_format (str, optional): Data format of output tensor, should be 'HWC' or
        'CHW'. Default: 'CHW'.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray): The input image with shape (H x W x C).
    - output(np.ndarray): A tensor with shape (C x H x W) or (H x W x C) according option data_format.

Returns:
    A callable object of ToTensor.

Examples:

    .. code-block:: pycon

        >>> from PIL import Image
        >>> import paddle
        >>> import paddle.vision.transforms as T
        >>> import paddle.vision.transforms.functional as F

        >>> img_arr = ((paddle.rand((4, 5, 3)) * 255.0).astype('uint8')).numpy()
        >>> fake_img = Image.fromarray(img_arr)
        >>> transform = T.ToTensor()
        >>> tensor = transform(fake_img)
        >>> print(tensor.shape)
        paddle.Size([3, 4, 5])
        >>> print(tensor.dtype)
        paddle.float32
r   data_formatc                0   > [         TU ]  U5        Xl        g r'   )superrg   r   )r*   r   r   rw   s      r,   rg   ToTensor.__init__  s    
 	&r0   c                B    [         R                  " XR                  5      $ )zo
Args:
    img (PIL.Image|np.ndarray): Image to be converted to tensor.

Returns:
    Tensor: Converted image.
)rD   	to_tensorr   r*   rO   s     r,   r   ToTensor._apply_image  s     {{3 0 011r0   )r   )CHWN)r   r   r   r   r5   r|   
r:   r;   r<   r=   r~   r   rg   r   r>   __classcell__rw   s   @r,   r   r   ^  sI    ,\ !  (-+/'$' )' 
	' '2 2r0   r   c                  b   ^  \ rS rSr% SrS\S'   S\S'     S
       SU 4S jjjrS rS	rU =r	$ )Resizei  a  Resize the input Image to the given size.

Args:
    size (int|list|tuple): Desired output size. If size is a sequence like
        (h, w), output size will be matched to this. If size is an int,
        smaller edge of the image will be matched to this number.
        i.e, if height > width, then image will be rescaled to
        (size * height / width, size)
    interpolation (int|str, optional): Interpolation method. Default: 'bilinear'.
        when use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC,
        - "box": Image.BOX,
        - "lanczos": Image.LANCZOS,
        - "hamming": Image.HAMMING
        when use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "area": cv2.INTER_AREA,
        - "bicubic": cv2.INTER_CUBIC,
        - "lanczos": cv2.INTER_LANCZOS4
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A resized image.

Returns:
    A callable object of Resize.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import Resize

        >>> fake_img = Image.fromarray((np.random.rand(256, 300, 3) * 255.).astype(np.uint8))
        >>> transform = Resize(size=224)
        >>> converted_img = transform(fake_img)
        >>> print(converted_img.size)
        (262, 224)
        >>> transform = Resize(size=(200,150))
        >>> converted_img = transform(fake_img)
        >>> print(converted_img.size)
        (150, 200)
r   rF   %_InterpolationPil | _InterpolationCv2interpolationc                   > [         TU ]  U5        [        U[        5      (       d&  [        U[        5      (       a  [        U5      S:X  d   eXl        X l        g )Nr@   )r   rg   rT   intr   rJ   rF   r   )r*   rF   r   r   rw   s       r,   rg   Resize.__init__  sM     	$$$tX&&3t9>	
 
 	*r0   c                X    [         R                  " XR                  U R                  5      $ r'   )rD   resizerF   r   r   s     r,   r   Resize._apply_image  s    xxYY(:(:;;r0   )r   rF   )bilinearN)rF   r   r   r   r   r   r5   r|   r   r   s   @r,   r   r     sZ    0d K88
 @J+/	++ =+ )	+
 
+ +< <r0   r   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'       S           SU 4S
 jjjrSS jrSS jrS r	Sr
U =r$ )RandomResizedCropi  a  Crop the input data to random size and aspect ratio.
A crop of random size (default: of 0.08 to 1.0) of the original size and a random
aspect ratio (default: of 3/4 to 1.33) of the original aspect ratio is made.
After applying crop transform, the input data will be resized to given size.

Args:
    size (int|list|tuple): Target size of output image, with (height, width) shape.
    scale (list|tuple, optional): Scale range of the cropped image before resizing, relatively to the origin
        image. Default: (0.08, 1.0).
    ratio (list|tuple, optional): Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33)
    interpolation (int|str, optional): Interpolation method. Default: 'bilinear'. when use pil backend,
        support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC,
        - "box": Image.BOX,
        - "lanczos": Image.LANCZOS,
        - "hamming": Image.HAMMING
        when use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "area": cv2.INTER_AREA,
        - "bicubic": cv2.INTER_CUBIC,
        - "lanczos": cv2.INTER_LANCZOS4
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A cropped image.

Returns:
    A callable object of RandomResizedCrop.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import RandomResizedCrop

        >>> transform = RandomResizedCrop(224)
        >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)

r   rF   Sequence[float]scaleratior   r   c                   > [         TU ]  U5        [        U[        5      (       a	  X4U l        OXl        US   US   ::  d   S5       eUS   US   ::  d   S5       eX l        X0l        X@l        g )Nr   r   z"scale should be of kind (min, max)"ratio should be of kind (min, max))r   rg   rT   r   rF   r   r   r   )r*   rF   r   r   r   r   rw   s         r,   rg   RandomResizedCrop.__init__   su     	dC  DIIQx58#I%II#Qx58#I%II#

*r0   c           	     
   [        U5      u  p4XC-  n[        U5       GH*  n[        R                  R                  " U R
                  6 U-  n[        S U R                   5       5      n[        R                  " [        R                  R                  " U6 5      n	[        [        [        R                  " Xy-  5      5      5      n
[        [        [        R                  " Xy-  5      5      5      nSU
s=:  a  U::  d  M  O  M  SUs=:  a  U::  d  M  O  M  [        R                  " SXK-
  5      n[        R                  " SX:-
  5      nXX4s  $    [        U5      [        U5      -  nU[        U R                  5      :  a-  Un
[        [        U
[        U R                  5      -  5      5      nOJU[!        U R                  5      :  a-  Un[        [        U[!        U R                  5      -  5      5      n
OUn
UnXK-
  S-  nX:-
  S-  nXX4$ )Nc              3  N   #    U  H  n[         R                  " U5      v   M     g 7fr'   mathlog.0xs     r,   	<genexpr>7RandomResizedCrop._dynamic_get_param.<locals>.<genexpr>9  s     >:adhhqkk:   #%r   r@   )rP   r   nprandomuniformr   rX   r   r   expr   roundsqrtrandintfloatr   rW   )r*   r   attemptswidthheightarea_target_area	log_ratioaspect_ratiowhr   jin_ratios                  r,   _dynamic_get_param$RandomResizedCrop._dynamic_get_param3  s   '.~xA))++TZZ84?K>4::>>I88BII$5$5y$ABLE$))K$>?@AAE$))K$>?@AA1~~~!a/6//NN1fj1NN1ei0Qz! ! <%-/c$**o%AE!c$**o-./ADJJ'AE!c$**o-./A AAZAY1Qzr0   c           
     @  ^ ^^^^	^
^^^^^ [        U5      u  mm
T
T-  m[        S T R                   5       5      m[        R                  " S/SSS9m[        R                  " S/SSS9n[        R
                  " S/SS9m[        R
                  " S/SS9m[        R                  " S/SS9T
S-   -  m	[        R                  " S/SS9TS-   -  mU
U4S jnUU
UU U4S	 jn[        R                  R                  R                  XETUTTT	T/5      u  mnmmm	mUU 4S
 jm[        R                  R                  R                  [        R                  " [        R                  " ST	:  T	T
:*  5      [        R                  " ST:  TT:*  5      5      UU	UUU4S jUU
U4S j5      $ )Nc              3  N   #    U  H  n[         R                  " U5      v   M     g 7fr'   r   r   s     r,   r   6RandomResizedCrop._static_get_param.<locals>.<genexpr>W  s     :z!$((1++zr   r   r   int32rH   
fill_valuedtype
   r   c                l   > [         R                  " X:  [         R                  " UT:  UT:  5      5      $ r'   paddlelogical_and
logical_or)countertenr   r   r   r   r   r   s         r,   cond1RandomResizedCrop._static_get_param.<locals>.condf  s7    %%!!IJ r0   c           
       >^^^^ [         R                  " S/TR                  S   TR                  S   S9T-  n[         R                  " [         R                  " S/T
S   T
S   S95      n[         R                  " [         R
                  " Xg-  5      5      R                  S5      m[         R                  " [         R
                  " Xg-  5      5      R                  S5      m[         R                  R                  R                  [         R                  " [         R                  " ST:  TT	:*  5      [         R                  " ST:  TT:*  5      5      UU	4S jU4S j5      m[         R                  R                  R                  [         R                  " [         R                  " ST:  TT	:*  5      [         R                  " ST:  TT:*  5      5      UU4S jU4S j5      mU S-  n XTTTT4$ )	Nr   r   rH   r   rW   r   c                 V   > [         R                  " S/STT -
  S9R                  S5      $ Nr   r   r  r   r   r   astype)r   r   s   r,   <lambda>CRandomResizedCrop._static_get_param.<locals>.body.<locals>.<lambda>  s&    aSaVaZHOOr0   c                    > T $ r'   r(   )r   s   r,   r  r	        r0   c                 V   > [         R                  " S/STT -
  S9R                  S5      $ r  r  )r   r   s   r,   r  r	    s&    aSaUQYGNNr0   c                    > T $ r'   r(   )r   s   r,   r  r	    r  r0   )r   r   r   r   r   r   r  staticnnr   r   )r   r   r   r   r   r   r   r   r   r   r   r*   r   s     ````  r,   body1RandomResizedCrop._static_get_param.<locals>.bodyo  s   aSdjjmAO  "::aSil	!ML V[[)CDELLA V[[)CDELLA   %%""&&q1ua6k:&&q1ua5j9 	A   %%""&&q1ua6k:&&q1ua5j9 	A qLGAq!++r0   c                  >^ ^^ [         R                  " T/5      R                  S5      m[         R                  " T /5      R                  S5      m T T-  m[         R                  R                  R                  TTR                  S   :  UU 4S jUUUU 4S j5      u  p#TR                  S5      U-
  S-  nT R                  S5      U-
  S-  nXEX2T4$ )Nfloat32r   c                    > TR                  S5      [        R                  " TT R                  S   -  5      R                  S5      /$ )Nr   r   )r  r   r   r   )r*   r   s   r,   r  KRandomResizedCrop._static_get_param.<locals>.central_crop.<locals>.<lambda>  s8    LL)LLA!67>>wGr0   c                    > [         R                  R                  R                  TTR                  S   :  U U4S jU U4S j5      $ )Nr   c                    > [         R                  " T TR                  S   -  5      R                  S5      T R                  S5      /$ )Nr   r   )r   r   r   r  )r   r*   s   r,   r  ]RandomResizedCrop._static_get_param.<locals>.central_crop.<locals>.<lambda>.<locals>.<lambda>  s8    Vdjjm%;<CCGLg.r0   c                 H   > TR                  S5      T R                  S5      /$ )Nr   )r  )r   r   s   r,   r  r    s    U\\'2FMM'4JKr0   )r   r  r  r   r   )r   r   r*   r   s   r,   r  r    s5    ((--tzz!}, Lr0   r   r@   )r   assignr  r  r  r   r   )	r   r   r   r   r   r   r   r   r*   s	   ``    @r,   central_crop9RandomResizedCrop._static_get_param.<locals>.central_crop  s    ]]F8,33I>FMM5'*11)<E v~H==##((4::a=(DA w'!+1Ag&*q0Aw&&r0   c                    > TTTTT /$ r'   r(   )r   r   r   r   r   s   r,   r  5RandomResizedCrop._static_get_param.<locals>.<lambda>  s    Q1a)r0   c                    > T " TT5      $ r'   r(   )r  r   r   s   r,   r  r    s    L/r0   )rP   rX   r   r   fullzerosonesr  r  
while_loopr   r   )r*   r   r   r   r   r  r   r  r   r   r   r   r   r   r   r   s   `     @@@@@@@@@@r,   _static_get_param#RandomResizedCrop._static_get_paramT  ss   '.v~:tzz::	++#!7
 kk#"G
 LL!G,LL!G,KK7+vz:KK7+uqy9	(	, (	,T $*==#3#3#>#>#q!Q2$
 aAq	'6 }}$$""1q5!v+6""1q5!u*5 *)/
 	
r0   c                   [         R                  " 5       (       a  U R                  U5      u  p#pEOU R                  U5      u  p#pEn[        R
                  " XX4U5      n[        R                  " XpR                  U R                  5      $ r'   )	r   in_dynamic_moder   r$  rD   cropr   rF   r   )r*   rO   r   r   r   r   r   cropped_imgs           r,   r   RandomResizedCrop._apply_image  sk    !!##005JA!Q"&"8"8"=A!ffSQ1-xxYY0B0BCCr0   )r   r   r   rF   ))g{Gz?      ?)g      ?gUUUUUU?r   N)rF   r   r   r   r   r   r   r   r   r   r5   r|   )r   )r:   r;   r<   r=   r~   r   rg   r   r$  r   r>   r   r   s   @r,   r   r     s    /b K88
 "-!3?I+/++ + 	+
 =+ )+ 
+ +&Bk
ZD Dr0   r   c                  R   ^  \ rS rSr% SrS\S'    S     S	U 4S jjjrS rSrU =r	$ )

CenterCropi  a;  Crops the given the input data at the center.

Args:
    size (int|list|tuple): Target size of output image, with (height, width) shape.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A cropped image.

Returns:
    A callable object of CenterCrop.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import CenterCrop

        >>> transform = CenterCrop(224)
        >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)

r   rF   c                   > [         TU ]  U5        [        U[        R                  5      (       a  [        U5      [        U5      4U l        g Xl        g r'   )r   rg   rT   rU   rV   r   rF   )r*   rF   r   rw   s      r,   rg   CenterCrop.__init__  s<     	dGNN++TCI.DIIr0   c                B    [         R                  " XR                  5      $ r'   )rD   center_croprF   r   s     r,   r   CenterCrop._apply_image  s    }}S)),,r0   rF   r'   )rF   r   r   r   r5   r|   r   r   s   @r,   r-  r-    sA    : K ?C!;	 - -r0   r-  c                  ^   ^  \ rS rSr% SrS\S'    S
     SU 4S jjjrS rS rS r	S	r
U =r$ )RandomHorizontalFlipi  a  Horizontally flip the input data randomly with a given probability.

Args:
    prob (float, optional): Probability of the input data being flipped. Should be in [0, 1]. Default: 0.5
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A horizontal flipped image.

Returns:
    A callable object of RandomHorizontalFlip.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> fake_img = paddle.to_tensor([[[0, 0, 1], [0, 0, 1], [1, 1, 1]]])
        >>> print(fake_img)
        Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
               [[[0, 0, 1],
                 [0, 0, 1],
                 [1, 1, 1]]])
        >>> transform = paddle.vision.transforms.RandomHorizontalFlip(prob=1)
        >>> result = transform(fake_img)
        >>> print(result)
        Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
               [[[1, 0, 0],
                 [1, 0, 0],
                 [1, 1, 1]]])

r   probc                h   > [         TU ]  U5        SUs=::  a  S::  d   S5       e   S5       eXl        g Nr   r   #probability must be between 0 and 1r   rg   r6  r*   r6  r   rw   s      r,   rg   RandomHorizontalFlip.__init__  8     	D~A~DDD~DDD~	r0   c                z    [         R                  " 5       (       a  U R                  U5      $ U R                  U5      $ r'   r   r'  _dynamic_apply_image_static_apply_imager   s     r,   r   !RandomHorizontalFlip._apply_image$  3    !!##,,S11++C00r0   c                x    [         R                   " 5       U R                  :  a  [        R                  " U5      $ U$ r'   )r   r6  rD   hflipr   s     r,   r@  )RandomHorizontalFlip._dynamic_apply_image*  '    ==?TYY&773<
r0   c                   ^ [         R                  R                  R                  [         R                  " SS9U R
                  :  U4S jU4S j5      $ )Nr   rH   c                 0   > [         R                  " T 5      $ r'   )rD   rE  rN   s   r,   r  :RandomHorizontalFlip._static_apply_image.<locals>.<lambda>2      AGGCLr0   c                    > T $ r'   r(   rN   s   r,   r  rL  3      Cr0   r   r  r  r   randr6  r   s    `r,   rA  (RandomHorizontalFlip._static_apply_image/  ;    }}$$KKd#dii/ 
 	
r0   r6        ?Nr6  r   r   r   r5   r|   r:   r;   r<   r=   r~   r   rg   r   r@  rA  r>   r   r   s   @r,   r5  r5    M     D K EI'A	 1

 
r0   r5  c                  ^   ^  \ rS rSr% SrS\S'    S
     SU 4S jjjrS rS rS r	S	r
U =r$ )RandomVerticalFlipi7  ag  Vertically flip the input data randomly with a given probability.

Args:
    prob (float, optional): Probability of the input data being flipped. Default: 0.5
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A vertical flipped image.

Returns:
    A callable object of RandomVerticalFlip.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> fake_img = paddle.to_tensor([[[0, 0, 1], [0, 0, 1], [1, 1, 1]]])
        >>> print(fake_img)
        Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
               [[[0, 0, 1],
                 [0, 0, 1],
                 [1, 1, 1]]])
        >>> transform = paddle.vision.transforms.RandomVerticalFlip(prob=1)
        >>> result = transform(fake_img)
        >>> print(result)
        Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
               [[[1, 1, 1],
                 [0, 0, 1],
                 [0, 0, 1]]])

r   r6  c                h   > [         TU ]  U5        SUs=::  a  S::  d   S5       e   S5       eXl        g r8  r:  r;  s      r,   rg   RandomVerticalFlip.__init__\  r=  r0   c                z    [         R                  " 5       (       a  U R                  U5      $ U R                  U5      $ r'   r?  r   s     r,   r   RandomVerticalFlip._apply_imagec  rC  r0   c                x    [         R                   " 5       U R                  :  a  [        R                  " U5      $ U$ r'   )r   r6  rD   vflipr   s     r,   r@  'RandomVerticalFlip._dynamic_apply_imagei  rG  r0   c                   ^ [         R                  R                  R                  [         R                  " SS9U R
                  :  U4S jU4S j5      $ )NrI  rJ  c                 0   > [         R                  " T 5      $ r'   )rD   ra  rN   s   r,   r  8RandomVerticalFlip._static_apply_image.<locals>.<lambda>q  rM  r0   c                    > T $ r'   r(   rN   s   r,   r  re  r  rO  r0   rP  r   s    `r,   rA  &RandomVerticalFlip._static_apply_imagen  rS  r0   rT  rU  rW  rX  r   s   @r,   r[  r[  7  rY  r0   r[  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'        S           SU 4S
 jjjrS rSrU =r	$ )	Normalizeiv  a  Normalize the input data with mean and standard deviation.
Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels,
this transform will normalize each channel of the input data.
``output[channel] = (input[channel] - mean[channel]) / std[channel]``

Args:
    mean (int|float|list|tuple, optional): Sequence of means for each channel.
    std (int|float|list|tuple, optional): Sequence of standard deviations for each channel.
    data_format (str, optional): Data format of img, should be 'HWC' or
        'CHW'. Default: 'CHW'.
    to_rgb (bool, optional): Whether to convert to rgb. Default: False.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A normalized array or tensor.

Returns:
    A callable object of Normalize.

Examples:

    .. code-block:: python
        :name: code-example

        >>> import paddle
        >>> from paddle.vision.transforms import Normalize
        >>> paddle.seed(2023)

        >>> normalize = Normalize(mean=[127.5, 127.5, 127.5],
        ...                         std=[127.5, 127.5, 127.5],
        ...                         data_format='HWC')
        ...
        >>> fake_img = paddle.rand([300,320,3]).numpy() * 255.
        >>> fake_img = normalize(fake_img)
        >>> print(fake_img.shape)
        (300, 320, 3)
        >>> print(fake_img.max(), fake_img.min())
        0.99999464 -0.9999929

r   meanstdr   r   boolto_rgbc                   > [         TU ]  U5        [        U[        R                  5      (       a  XU/n[        U[        R                  5      (       a  X"U/nXl        X l        X0l        X@l        g r'   )	r   rg   rT   rU   rV   rj  rk  r   rm  )r*   rj  rk  r   rm  r   rw   s         r,   rg   Normalize.__init__  s\     	dGNN++%Dc7>>**S/C	&r0   c                    [         R                  " XR                  U R                  U R                  U R
                  5      $ r'   )rD   	normalizerj  rk  r   rm  r   s     r,   r   Normalize._apply_image  s.    {{DHHd&6&6
 	
r0   )r   rj  rk  rm  )        r+  r   FN)rj  float | Sequence[float]rk  rt  r   r   rm  rl  r   r   r5   r|   r   r   s   @r,   ri  ri  v  s    (T 	  L ),'*',+/% % %	
  ) 
 (
 
r0   ri  c                  T   ^  \ rS rSr% SrS\S'     S     S	U 4S jjjrS rSrU =r	$ )
	Transposei  a*  Transpose input data to a target format.
For example, most transforms use HWC mode image,
while the Neural Network might use CHW mode input tensor.
output image will be an instance of numpy.ndarray.

Args:
    order (list|tuple, optional): Target order of input data. Default: (2, 0, 1).
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(np.ndarray|Paddle.Tensor): A transposed array or tensor. If input
        is a PIL.Image, output will be converted to np.ndarray automatically.

Returns:
    A callable object of Transpose.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import Transpose

        >>> transform = Transpose()
        >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.shape)
        (3, 300, 320)

Sequence[int]orderc                0   > [         TU ]  U5        Xl        g r'   )r   rg   rx  )r*   rx  r   rw   s      r,   rg   Transpose.__init__  s    
 	
r0   c                b   [         R                  " U5      (       a  UR                  U R                  5      $ [         R                  " U5      (       a  [
        R                  " U5      n[        UR                  5      S:X  a  US[
        R                  4   nUR                  U R                  5      $ )Nr@   .)
rD   rI   	transposerx  rE   r   asarrayrJ   rH   newaxisr   s     r,   r   Transpose._apply_image  sw    c""==,,??3**S/Csyy>Qc2::o&C}}TZZ((r0   )rx  ))r@   r   r   N)rx  rw  r   r   r5   r|   r   r   s   @r,   rv  rv    sI    B   )+/ ) 
	 	) 	)r0   rv  c                  R   ^  \ rS rSr% SrS\S'    S     S	U 4S jjjrS rSrU =r	$ )
BrightnessTransformi  aJ  Adjust brightness of the image.

Args:
    value (float): How much to adjust the brightness. Can be any
        non negative number. 0 gives the original image.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in brightness.

Returns:
    A callable object of BrightnessTransform.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import BrightnessTransform
        >>> np.random.seed(2023)

        >>> transform = BrightnessTransform(0.4)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> print(fake_img.load()[1,1]) # type: ignore[index]
        (60, 169, 34)
        >>> # doctest: +SKIP('random sample in Brightness function')
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.load()[1,1])
        (68, 192, 38)

r   rZ   c                F   > [         TU ]  U5        [        US5      U l        g )N
brightnessr   rg   r_   rZ   r*   rZ   r   rw   s      r,   rg   BrightnessTransform.__init__        	!%6
r0   c                    U R                   c  U$ [        R                  " U R                   S   U R                   S   5      n[        R                  " X5      $ Nr   r   )rZ   r   r   rD   adjust_brightness)r*   rO   brightness_factors      r,   r    BrightnessTransform._apply_image#  C    ::J"NN4::a=$**Q-H""3::r0   rZ   r'   rZ   r   r   r   r5   r|   r   r   s   @r,   r  r    sC     D L @D77"<7	7 7; ;r0   r  c                  R   ^  \ rS rSr% SrS\S'    S     S	U 4S jjjrS rSrU =r	$ )
ContrastTransformi+  az  Adjust contrast of the image.

Args:
    value (float): How much to adjust the contrast. Can be any
        non negative number. 0 gives the original image.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in contrast.

Returns:
    A callable object of ContrastTransform.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import ContrastTransform

        >>> transform = ContrastTransform(0.4)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)

r   rZ   c                h   > [         TU ]  U5        US:  a  [        S5      e[        US5      U l        g )Nr   z%contrast value should be non-negativecontrast)r   rg   rK   r_   rZ   r  s      r,   rg   ContrastTransform.__init__L  s3     	19DEE!%4
r0   c                    U R                   c  U$ [        R                  " U R                   S   U R                   S   5      n[        R                  " X5      $ r  )rZ   r   r   rD   adjust_contrast)r*   rO   contrast_factors      r,   r   ContrastTransform._apply_imageT  sB    ::J ..A

1F  66r0   r  r'   r  r   r   s   @r,   r  r  +  sB    < L @D55"<5	5 57 7r0   r  c                  R   ^  \ rS rSr% SrS\S'    S     S	U 4S jjjrS rSrU =r	$ )
SaturationTransformi\  a  Adjust saturation of the image.

Args:
    value (float): How much to adjust the saturation. Can be any
        non negative number. 0 gives the original image.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in saturation.

Returns:
    A callable object of SaturationTransform.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import SaturationTransform

        >>> transform = SaturationTransform(0.4)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)
r   rZ   c                F   > [         TU ]  U5        [        US5      U l        g )N
saturationr  r  s      r,   rg   SaturationTransform.__init__|  r  r0   c                    U R                   c  U$ [        R                  " U R                   S   U R                   S   5      n[        R                  " X5      $ r  )rZ   r   r   rD   adjust_saturation)r*   rO   saturation_factors      r,   r    SaturationTransform._apply_image  r  r0   r  r'   r  r   r   s   @r,   r  r  \  sB    : L @D77"<7	7 7; ;r0   r  c                  R   ^  \ rS rSr% SrS\S'    S     S	U 4S jjjrS rSrU =r	$ )
HueTransformi  aa  Adjust hue of the image.

Args:
    value (float): How much to adjust the hue. Can be any number
        between 0 and 0.5, 0 gives the original image.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in hue.

Returns:
    A callable object of HueTransform.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import HueTransform

        >>> transform = HueTransform(0.4)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)

r   rZ   c                H   > [         TU ]  U5        [        USSSSS9U l        g )Nhuer   )g      rV  F)r\   r]   r^   r  r  s      r,   rg   HueTransform.__init__  s)     	!5+%

r0   c                    U R                   c  U$ [        R                  " U R                   S   U R                   S   5      n[        R                  " X5      $ r  )rZ   r   r   rD   
adjust_hue)r*   rO   
hue_factors      r,   r   HueTransform._apply_image  s@    ::J^^DJJqM4::a=A
||C,,r0   r  r'   r  r   r   s   @r,   r  r    sB    < L @D

"<
	
 
- -r0   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'        S           SU 4S jjjrS	 rS
 rSr	U =r
$ )ColorJitteri  a  Randomly change the brightness, contrast, saturation and hue of an image.

Args:
    brightness (float, optional): How much to jitter brightness.
        Chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. Should be non negative numbers. Default: 0.
    contrast (float, optional): How much to jitter contrast.
        Chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. Should be non negative numbers. Default: 0.
    saturation (float, optional): How much to jitter saturation.
        Chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. Should be non negative numbers. Default: 0.
    hue (float, optional): How much to jitter hue.
        Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5. Default: 0.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A color jittered image.

Returns:
    A callable object of ColorJitter.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import ColorJitter

        >>> transform = ColorJitter(0.4, 0.4, 0.4, 0.4)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (224, 224)

r   r  r  r  r  c                T   > [         TU ]  U5        Xl        X l        X0l        X@l        g r'   )r   rg   r  r  r  r  )r*   r  r  r  r  r   rw   s         r,   rg   ColorJitter.__init__  s&     	$ $r0   c                   / nUb$  UR                  [        XR                  5      5        Ub$  UR                  [        X R                  5      5        Ub$  UR                  [	        X0R                  5      5        Ub$  UR                  [        X@R                  5      5        [        R                  " U5        [        U5      nU$ )zGet a randomized transform to be applied on image.

Arguments are same as that of __init__.

Returns:
    Transform which randomly adjusts brightness, contrast and
    saturation in a random order.
)	r   r  r   r  r  r  r   shufflera   )r*   r  r  r  r  rd   	transforms          r,   
_get_paramColorJitter._get_param  s     
!1*iiHI/))DE!1*iiHI?l3		:;z"J'	r0   c                    U R                  U R                  U R                  U R                  U R                  5      nU" U5      $ )zX
Args:
    img (PIL Image): Input image.

Returns:
    PIL Image: Color jittered image.
)r  r  r  r  r  )r*   rO   r  s      r,   r   ColorJitter._apply_image  s7     OOOOT]]DOOTXX
	 ~r0   )r  r  r  r  )r   r   r   r   N)r  r   r  r   r  r   r  r   r   r   r5   r|   r:   r;   r<   r=   r~   r   rg   r  r   r>   r   r   s   @r,   r  r    s    "H O	J +/  	
  ) 
 8 r0   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'        S             SU 4S jjjrS rS rSr	U =r
$ )
RandomCropi  a	  Crops the given CV Image at a random location.

Args:
    size (sequence|int): Desired output size of the crop. If size is an
        int instead of sequence like (h, w), a square crop (size, size) is
        made.
    padding (int|sequence, optional): Optional padding on each border
        of the image. If a sequence of length 4 is provided, it is used to pad left,
        top, right, bottom borders respectively. Default: None, without padding.
    pad_if_needed (boolean, optional): It will pad the image if smaller than the
        desired size to avoid raising an exception. Default: False.
    fill (float|tuple, optional): Pixel fill value for constant fill. 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. Default: 0.
    padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default: 'constant'.

        - constant: pads with a constant value, this value is specified with fill

        - edge: pads with the last value on the edge of the image

        - reflect: pads with reflection of image (without repeating the last value on the edge)

               padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
               will result in [3, 2, 1, 2, 3, 4, 3, 2]

        - symmetric: pads with reflection of image (repeating the last value on the edge)

                 padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
                 will result in [2, 1, 1, 2, 3, 4, 4, 3]
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A random cropped image.

Returns:
    A callable object of RandomCrop.

Examples:

    .. code-block:: pycon
        :name: code-example1

        >>> import paddle
        >>> from paddle.vision.transforms import RandomCrop
        >>> transform = RandomCrop(224)

        >>> fake_img = paddle.randint(0, 255, shape=(3, 324, 300), dtype='int32')
        >>> print(fake_img.shape)
        paddle.Size([3, 324, 300])

        >>> crop_img = transform(fake_img)
        >>> print(crop_img.shape)
        paddle.Size([3, 224, 224])
r   rF   Size2 | Size4 | Nonepaddingrl  pad_if_neededr   fillr   padding_modec                   > [         TU ]  U5        [        U[        R                  5      (       a  [        U5      [        U5      4U l        OXl        X l        X0l        X@l	        XPl
        g r'   )r   rg   rT   rU   rV   r   rF   r  r  r  r  )r*   rF   r  r  r  r  r   rw   s          r,   rg   RandomCrop.__init__\  sR     	dGNN++TCI.DII*	(r0   c                @   [        U5      u  p4Uu  pVX6:X  a
  XE:X  a  SSXC4$ [        R                  " 5       (       a3  [        R                  " SXE-
  5      n[        R                  " SX6-
  5      nO.[        R                  " SXE-
  S9n[        R                  " SX6-
  S9nXxXV4$ )zGet parameters for ``crop`` for a random crop.

Args:
    img (PIL Image): Image to be cropped.
    output_size (tuple): Expected output size of the crop.

Returns:
    tuple: params (i, j, h, w) to be passed to ``crop`` for random crop.
r   )lowhigh)rP   r   r'  r   r   )	r*   rO   output_sizer   r   thtwr   r   s	            r,   r  RandomCrop._get_paramo  s     s#7qwa:!!##q!&)Aq!&)A1162A1162AR|r0   c                   U R                   b6  [        R                  " XR                   U R                  U R                  5      n[        U5      u  p#U R                  (       aP  X R                  S   :  a>  [        R                  " XR                  S   U-
  S4U R                  U R                  5      nU R                  (       aQ  X0R                  S   :  a?  [        R                  " USU R                  S   U-
  4U R                  U R                  5      nU R                  XR                  5      u  pEp2[        R                  " XXSU5      $ )zY
Args:
    img (PIL Image): Image to be cropped.

Returns:
    PIL Image: Cropped image.
r   r   )
r  rD   padr  r  rP   r  rF   r  r(  )r*   rO   r   r   r   r   s         r,   r   RandomCrop._apply_image  s     <<#%%\\499d6G6GHCs# !iil"2%%iilQ&*DIIt7H7HC !iil"2%%a1)*DIIt7H7HC __S))4
avvcaA&&r0   )r  r  r  r  rF   )NFr   constantN)rF   r   r  r  r  rl  r  r   r  r   r   r   r5   r|   r  r   s   @r,   r  r    s    6p K!!
K
 )-#%/+/)) &) 	)
 ) #) )) 
) )&.' 'r0   r  c                  r   ^  \ rS rSr% SrS\S'   S\S'   S\S'      S         SU 4S	 jjjrS
 rSrU =r	$ )Padi  a  Pads the given CV Image on all sides with the given "pad" value.

Args:
    padding (int|list|tuple): Padding on each border. If a single int is provided this
        is used to pad all borders. If list/tuple of length 2 is provided this is the padding
        on left/right and top/bottom respectively. If a list/tuple of length 4 is provided
        this is the padding for the left, top, right and bottom borders
        respectively.
    fill (int|list|tuple): Pixel fill value for constant fill. Default is 0. If a list/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 (str): Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
        ``constant`` means pads with a constant value, this value is specified with fill.
        ``edge`` means pads with the last value at the edge of the image.
        ``reflect`` means pads with reflection of image (without repeating the last value on the edge)
        padding ``[1, 2, 3, 4]`` with 2 elements on both sides in reflect mode
        will result in ``[3, 2, 1, 2, 3, 4, 3, 2]``.
        ``symmetric`` means pads with reflection of image (repeating the last value on the edge)
        padding ``[1, 2, 3, 4]`` with 2 elements on both sides in symmetric mode
        will result in ``[2, 1, 1, 2, 3, 4, 4, 3]``.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A padded image.

Returns:
    A callable object of Pad.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import Pad

        >>> transform = Pad(2)
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (228, 228)
Size2 | Size4r  r   r  r   r  c                  > [        U[        R                  [        [        45      (       d   e[        U[        R                  [
        [        [        45      (       d   eUS;   d   e[        U[        5      (       a  [	        U5      n[        U[        5      (       a  [	        U5      n[        U[        5      (       a)  [        U5      S;  a  [        S[        U5       S3-   5      e[        TU ])  U5        Xl        X l        X0l        g )N)r  edgereflect	symmetricr@   rC   z9Padding must be an int or a 2, or 4 element tuple, not a z element tuple)rT   rU   rV   rY   rX   r}   r   rJ   rK   r   rg   r  r  r  )r*   r  r  r  r   rw   s        r,   rg   Pad.__init__  s     'GNND%#@AAAA$dE BCCCCKKKKgt$$GnGdD!!;Dgx((S\-GK\N.12 
 		(r0   c                n    [         R                  " XR                  U R                  U R                  5      $ )zW
Args:
    img (PIL Image): Image to be padded.

Returns:
    PIL Image: Padded image.
)rD   r  r  r  r  r   s     r,   r   Pad._apply_image  s%     uuS,,		43D3DEEr0   )r  r  r  )r   r  N)
r  r  r  r   r  r   r   r   r5   r|   r   r   s   @r,   r  r    sm    *X 
K
 %/+/)) ) #	)
 )) 
) )6F Fr0   r  c                   [        U5      S:  a  US   O*SR                  U Vs/ s H  n[        U5      PM     sn5      n[        U [        5      (       d  [        U SU S35      e[        U 5      U;  a  [        U SU S35      eg s  snf )Nr@   r   z or z  should be a sequence of length .z should be sequence of length )rJ   joinr}   rT   r   rL   rK   )r   r[   	req_sizessmsgs        r,   _check_sequence_inputr    s     y>A 	![[)4)Q#a&)45 
 a""4& @QGHH
1vYD6!?uAFGG 	 5s   Bc                    [        U [        R                  5      (       a  U S:  a  [        SU S35      eU * U /n O[	        XU5        U  Vs/ s H  n[        U5      PM     sn$ s  snf )Nr   rS   z) is a single number, it must be positive.)rT   rU   rV   rK   r  r   )r   r[   r  ds       r,   _setup_angler    sg    !W^^$$q5dVDE  RGay1 aE!Ha   s   A#c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'          S                 SU 4S jjjr SS jrS rSr	U =r
$ )RandomAffinei  a  Random affine transformation of the image.

Args:
    degrees (int|float|tuple): The angle interval of the random rotation.
        If set as a number instead of sequence like (min, max), the range of degrees
        will be (-degrees, +degrees) in clockwise order. If set 0, will not rotate.
    translate (tuple, optional): Maximum absolute fraction for horizontal and vertical translations.
        For example translate=(a, b), then horizontal shift is randomly sampled in the range -img_width * a < dx < img_width * a
        and vertical shift is randomly sampled in the range -img_height * b < dy < img_height * b.
        Default is None, will not translate.
    scale (tuple, optional): Scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b.
        Default is None, will keep original scale and not scale.
    shear (sequence or number, optional): Range of degrees to shear, ranges from -180 to 180 in clockwise order.
        If set as a number, a shear parallel to the x axis in the range (-shear, +shear) will be applied.
        Else if set as a sequence of 2 values a shear parallel to the x axis in the range (shear[0], shear[1]) will be applied.
        Else if set as a sequence of 4 values, a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
        Default is None, will not apply shear.
    interpolation (str, optional): Interpolation method. If omitted, or if the
        image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST
        according the backend.
        When use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        When use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    fill (int|list|tuple, optional): Pixel fill value for the area outside the transformed
        image. If given a number, the value is used for all bands respectively.
    center (tuple|None, optional): Optional center of rotation, (x, y).
        Origin is the upper left corner.
        Default is the center of the image.
    keys (list[str]|tuple[str]|None, optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): An affined image.

Returns:
    A callable object of RandomAffine.

Examples:

    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.transforms import RandomAffine

        >>> transform = RandomAffine(
        ...     [-90, 90],
        ...     translate=[0.2, 0.2],
        ...     scale=[0.5, 0.5],
        ...     shear=[-10, 10],
        ... )
        >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32)
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.shape)
        paddle.Size([3, 256, 300])
)float | list[float] | tuple[float, float]degrees(list[float] | tuple[float, float] | None	translater   Tfloat | list[float] | tuple[float, float] | tuple[float, float, float, float] | Noneshearr   r   r   r  r\   c	                  > [        USSS9U l        [        TU ]  U5        US;   d   eXPl        Ub.  [        USSS9  U H  n	SU	s=::  a  S::  a  M  O  [        S	5      e   X l        Ub%  [        US
SS9  U H  n
U
S::  d  M  [        S5      e   X0l        Ub  [        USSS9U l	        OX@l	        Uc  SnO0[        U[        [        R                  45      (       d  [        S5      eX`l        Ub  [        USSS9  Xpl        g )Nr  r@   )r[   r  nearestr   bicubicr  )r  rs  r+  z,translation values should be between 0 and 1r   r   zscale values should be positiver  r  z-Fill should be either a sequence or a number.r\   )r  r  r   rg   r   r  rK   r  r   r  rT   r   rU   rV   rL   r  r\   )r*   r  r  r   r  r   r  r\   r   ry   r  rw   s              r,   rg   RandomAffine.__init___  s   " $G)tL BBBB* !)[DIqC$F  
 #!%DA6$%FGG  
%e'VLDJJ<DD8W^^"<==KLL	!&(dCr0   c                   [         R                  " US   US   5      nUbn  [        US   US   -  5      n[        US   US   -  5      n[        [         R                  " U* U5      5      n	[        [         R                  " U* U5      5      n
X4nOSnUb  [         R                  " US   US   5      nOSnSu  pUbI  [         R                  " US   US   5      n[	        U5      S:X  a  [         R                  " US   US   5      nX4nXkX4$ )	zhGet parameters for affine transformation

Returns:
    params to be passed to the affine transformation
r   r   )r   r   r+  )rs  rs  rC   r@   rB   )r   r   r   r   rJ   )r*   img_sizer  r  scale_rangesshearsanglemax_dxmax_dytxtytranslationsr   shear_xshear_yr  s                   r,   r  RandomAffine._get_param  s
    wqz71:6 9Q<(1+56F9Q<(1+56FV^^VGV45BV^^VGV45B8L!L#NN<?LODEE#nnVAYq	:G6{a ..F1I>"E00r0   c                   [        U5      u  p#X#/nU R                  X@R                  U R                  U R                  U R
                  5      n[        R                  " U/UQ7U R                  U R                  U R                  S.6$ )z
Args:
    img (PIL.Image|np.array): Image to be affine transformed.

Returns:
    PIL.Image or np.array: Affine transformed image.
)r   r  r\   )rP   r  r  r  r   r  rD   affiner   r  r\   )r*   rO   r   r   r  rets         r,   r   RandomAffine._apply_image  sz     s#6oollDNNDJJ


 xx

 ,,;;
 	
r0   )r\   r  r  r   r   r  r  )NNNr  r   NN)r  r  r  r  r   r  r  r  r   r   r  r   r\   r  r   r   r5   r|   )NNNr  r   s   @r,   r  r    s    ;z 767733	 98
K44
 ?C:> ?H;?+/4:4 <4 8	44 =4 4 94 )4  
!4 4n LP1B
 
r0   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'        S             SU 4S jjjrS rS rSr	U =r
$ )RandomRotationi  a  Rotates the image by angle.

Args:
    degrees (sequence or float or int): Range of degrees to select from.
        If degrees is a number instead of sequence like (min, max), the range of degrees
        will be (-degrees, +degrees) clockwise order.
    interpolation (str, optional): Interpolation method. If omitted, or if the
        image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST
        according the backend. when use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        when use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    expand (bool|optional): Optional expansion flag. Default: False.
        If true, expands the output to make it large enough to hold the entire rotated image.
        If false or omitted, make the output image the same size as the input image.
        Note that the expand flag assumes rotation around the center and no translation.
    center (2-tuple|optional): Optional center of rotation.
        Origin is the upper left corner.
        Default is the center of the image.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A rotated image.

Returns:
    A callable object of RandomRotation.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import RandomRotation

        >>> transform = RandomRotation(90)
        >>> fake_img = Image.fromarray((np.random.rand(200, 150, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.size)
        (150, 200)
r   r  r   r   rl  expandztuple[float, float]r\   r   r  c                
  > [        U[        R                  5      (       a  US:  a  [        S5      eU* U4U l        O [        U5      S:w  a  [        S5      eXl        [        TU ]  U5        X l        X0l	        X@l
        XPl        g )Nr   z3If degrees is a single number, it must be positive.r@   z.If degrees is a sequence, it must be of len 2.)rT   rU   rV   rK   r  rJ   r   rg   r   r  r\   r  )r*   r  r   r  r\   r  r   rw   s          r,   rg   RandomRotation.__init__  s     gw~~..{ I  %Hg.DL7|q  D  #L*	r0   c                    [         R                  " 5       (       a  [        R                  " US   US   5      nU$ [         R                  " S/SUS   US   S9nU$ )Nr   r   r  )r   r   rW   )r   r'  r   r   )r*   r  r  s      r,   r  RandomRotation._get_param!  sZ    !!##NN71:wqz:E 	 NN9'!*'!*E r0   c                    U R                  U R                  5      n[        R                  " XU R                  U R
                  U R                  U R                  5      $ )zn
Args:
    img (PIL.Image|np.array): Image to be rotated.

Returns:
    PIL.Image or np.array: Rotated image.
)r  r  rD   rotater   r  r\   r  )r*   rO   r  s      r,   r   RandomRotation._apply_image+  sD     -xx**DKKdii
 	
r0   )r\   r  r  r  r   )r  FNr   N)r  rt  r   r   r  rl  r\   ztuple[float, float] | Noner  r   r   r   r5   r|   r  r   s   @r,   r   r     s    -^ 88L
K
 @I-1+/( = 	
 +  ) 
 8
 
r0   r   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'        S           SU 4S
 jjjr        SS jrS rSr	U =r
$ )RandomPerspectivei;  a  Random perspective transformation with a given probability.

Args:
    prob (float, optional): Probability of using transformation, ranges from
        0 to 1, default is 0.5.
    distortion_scale (float, optional): Degree of distortion, ranges from
        0 to 1, default is 0.5.
    interpolation (str, optional): Interpolation method. If omitted, or if
        the image has only one channel, it is set to PIL.Image.NEAREST or
        cv2.INTER_NEAREST.
        When use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        When use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    fill (int|list|tuple, optional): Pixel fill value for the area outside the transformed
        image. If given a number, the value is used for all bands respectively.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): A perspectived image.

Returns:
    A callable object of RandomPerspective.

Examples:

    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.transforms import RandomPerspective

        >>> transform = RandomPerspective(prob=1.0, distortion_scale=0.9)
        >>> fake_img = paddle.randn((3, 200, 150)).astype(paddle.float32)
        >>> fake_img = transform(fake_img)
        >>> print(fake_img.shape)
        paddle.Size([3, 200, 150])
r   r6  distortion_scaler   r   r   r  c                6  > [         TU ]  U5        SUs=::  a  S::  d   S5       e   S5       eSUs=::  a  S::  d   S5       e   S5       eUS;   d   e[        U[        R                  [
        [        [        45      (       d   eXl        X l	        X0l
        X@l        g )Nr   r   r9  z(distortion_scale must be between 0 and 1r  )r   rg   rT   rU   rV   r}   rY   rX   r6  r  r   r  )r*   r6  r  r   r  r   rw   s         r,   rg   RandomPerspective.__init__l  s     	D~A~DDD~DDD~$)) 	
6	
) 	
6	
)  BBBB$dE BCCCC	 0*	r0   c           
     P   US-  nUS-  n[        [        R                  " S[        X5-  5      S-   5      5      [        [        R                  " S[        X4-  5      S-   5      5      /n[        [        R                  " U[        X5-  5      -
  S-
  U5      5      [        [        R                  " S[        X4-  5      S-   5      5      /n[        [        R                  " U[        X5-  5      -
  S-
  U5      5      [        [        R                  " U[        X4-  5      -
  S-
  U5      5      /n[        [        R                  " S[        X5-  5      S-   5      5      [        [        R                  " U[        X4-  5      -
  S-
  U5      5      /n	SS/US-
  S/US-
  US-
  /SUS-
  //n
XgX/nX4$ )z
Returns:
    startpoints (list[list[int]]): [top-left, top-right, bottom-right, bottom-left] of the original image,
    endpoints (list[list[int]]): [top-left, top-right, bottom-right, bottom-left] of the transformed image.
r@   r   r   )r   r   r   )r*   r   r   r  half_height
half_widthtoplefttoprightbotrightbotleftstartpoints	endpointss               r,   
get_paramsRandomPerspective.get_params  s    kaZ
q#&6&C"Dq"HIJq#&6&D"E"IJK

 C 0 =>>BE
 q#&6&D"E"IJK
 C 0 =>>BE
 S!1!?@@1Df
 q#&6&C"Dq"HIJS!1!?@@1Df
 FQYNQY
#
O	
 :	%%r0   c                    [        U5      u  p#[        R                  " 5       U R                  :  aJ  U R                  X#U R                  5      u  pE[
        R                  " XXPR                  U R                  5      $ U$ )z
Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be Perspectively transformed.

Returns:
    PIL.Image|np.array|paddle.Tensor: Perspectively transformed image.
)	rP   r   r6  r  r  rD   perspectiver   r  )r*   rO   r   r   r  r  s         r,   r   RandomPerspective._apply_image  si     (,==?TYY&%)__t44&"K ==)-?-?  
r0   )r  r  r   r6  )rV  rV  r  r   N)r6  r   r  r   r   r   r  r   r   r   r5   r|   )r   r   r   r   r  r   r5   z'tuple[list[list[int]], list[list[int]]])r:   r;   r<   r=   r~   r   rg   r  r   r>   r   r   s   @r,   r
  r
  ;  s    )V K88
K "%?H+/   =	
  ) 
 *2&2&"%2&9>2&	02&h r0   r
  c                  T   ^  \ rS rSr% SrS\S'     S     S	U 4S jjjrS rSrU =r	$ )
	Grayscalei  a  Converts image to grayscale.

Args:
    num_output_channels (int, optional): (1 or 3) number of channels desired for output image. Default: 1.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
    - output(PIL.Image|np.ndarray|Paddle.Tensor): Grayscale version of the input image.
        - If output_channels == 1 : returned image is single channel
        - If output_channels == 3 : returned image is 3 channel with r == g == b

Returns:
    A callable object of Grayscale.

Examples:

    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import Grayscale

        >>> transform = Grayscale()
        >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
        >>> fake_img = transform(fake_img)
        >>> print(np.array(fake_img).shape)
        (224, 224)
r   num_output_channelsc                0   > [         TU ]  U5        Xl        g r'   )r   rg   r  )r*   r  r   rw   s      r,   rg   Grayscale.__init__  s    
 	#6 r0   c                B    [         R                  " XR                  5      $ )zt
Args:
    img (PIL Image): Image to be converted to grayscale.

Returns:
    PIL Image: Randomly grayscaled image.
)rD   to_grayscaler  r   s     r,   r   Grayscale._apply_image  s     ~~c#;#;<<r0   )r  )r   N)r  r   r   r   r5   r|   r   r   s   @r,   r  r    sH    <  $%+/7 7 )7 
	7 7= =r0   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
\S'         S             SU 4S jjjrS rS rS r	S r
S rSrU =r$ )RandomErasingi  aH  Erase the pixels in a rectangle region selected randomly.

Args:
    prob (float, optional): Probability of the input data being erased. Default: 0.5.
    scale (sequence, optional): The proportional range of the erased area to the input image.
                                Default: (0.02, 0.33).
    ratio (sequence, optional): Aspect ratio range of the erased area. Default: (0.3, 3.3).
    value (int|float|sequence|str, optional): The value each pixel in erased area will be replaced with.
                           If value is a single number, all pixels will be erased with this value.
                           If value is a sequence with length 3, the R, G, B channels will be erased
                           respectively. If value is set to "random", each pixel will be erased with
                           random values. Default: 0.
    inplace (bool, optional): Whether this transform is inplace. Default: False.
    keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.

Shape:
    - img(paddle.Tensor | np.array | PIL.Image): The input image. For Tensor input, the shape should be (C, H, W).
             For np.array input, the shape should be (H, W, C).
    - output(paddle.Tensor | np.array | PIL.Image): A random erased image.

Returns:
    A callable object of RandomErasing.

Examples:

    .. code-block:: python

        >>> import paddle

        >>> fake_img = paddle.randn((1, 5, 5)).astype(paddle.float32)
        >>> transform = paddle.vision.transforms.RandomErasing()
        >>> result = transform(fake_img)
        >>> # doctest: +SKIP('random sample')
        >>> print(result)
        Tensor(shape=[1, 5, 5], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [[[-0.22141267, -0.71004093,  1.71224928,  2.99622107, -0.82959402],
          [ 0.36916021, -0.25601348,  0.86669374,  1.27504587, -0.56462914],
          [-0.45704395, -0.87613666,  1.12195814, -0.87974882,  0.04902615],
          [-0.91549885, -0.15066874,  1.26381516,  0.        ,  0.        ],
          [ 0.87887472, -1.59914243, -0.73970413,  0.        ,  0.        ]]])

r   r6  r   r   r   z#int | float | Sequence[float] | strrZ   rl  inplacec                H  > [         TU ]  U5        [        U[        [        45      (       d   S5       eUS   S:  a  US   S::  a  US   US   ::  d   S5       e[        U[        [        45      (       d   S5       eUS   S:  a  US   US   ::  d   S5       eUS:  a  US::  d   S5       e[        U[
        R                  [        [        [        45      (       d   S5       e[        U[        5      (       a  US	:w  a  [        S
5      eXl	        X l
        X0l        X@l        XPl        g )Nzscale should be a tuple or listr   r   z6scale should be of kind (min, max) and in range [0, 1]zratio should be a tuple or listr   z)The probability should be in range [0, 1]z,value should be a number, tuple, list or strr   z'value must be 'random' when type is str)r   rg   rT   rX   rY   rU   rV   r}   rK   r6  r   r   rZ   r&  )r*   r6  r   r   rZ   r&  r   rw   s          r,   rg   RandomErasing.__init__0  s>    	%%// 	
-	
/ Qx1}qQ58uQx3G 	
D	
G %%// 	
-	
/ Qx1}qU1X!5 	
0	
5 qyTQY 	
7	
& %'..#ud!CDD 	
:	
D eS!!ex&7FGG	


r0   c           	        [         R                  " U5      (       aL  [        R                  " U5      R	                  [        R
                  5      R                  nUS   US   US   pnO[         R                  " U5      (       a-  UR                  S   UR                  S   UR                  S   pnOG[         R                  " U5      (       a,  UR                  S   UR                  S   UR                  S   pvnWW-  n	[        R                  " U5      n
[        S5       GH  n[        R                  R                  " U6 U	-  n[        R                  " [        R                  R                  " U
6 5      n[        [        [        R                   " X-  5      5      5      n[        [        [        R                   " X-  5      5      5      nX:  d  X:  a  M  [         R                  " U5      (       aZ  Uc0  ["        R$                  " WX/S9R	                  UR&                  5      nOk["        R(                  " XAR&                  S9SS2SS4   nODUc#  [        R                  R%                  XW/S9S	-  nO[        R*                  " U5      SSSS24   n[        R                  R-                  S
Xn-
  S-   5      n[        R                  R-                  S
X-
  S-   5      nUUXU4s  $    S
S
XgU4$ )a  Get parameters for ``erase`` for a random erasing in dynamic mode.

Args:
    img (paddle.Tensor | np.array | PIL.Image): Image to be erased.
    scale (sequence, optional): The proportional range of the erased area to the input image.
    ratio (sequence, optional): Aspect ratio range of the erased area.
    value (sequence | None): The value each pixel in erased area will be replaced with.
                       If value is a sequence with length 3, the R, G, B channels will be erased
                       respectively. If value is None, each pixel will be erased with random values.

Returns:
    tuple: params (i, j, h, w, v) to be passed to ``erase`` for random erase.
rA   r   NrJ  r   r3     r   r   )rD   rE   r   r}  r  uint8rH   rG   rI   r   r   r   r   r   r   r   r   r   normalr   r   arrayr   )r*   rO   r   r   rZ   rH   r   r   cimg_arear   r   
erase_arear   erase_herase_wvtoplefts                      r,   r    RandomErasing._dynamic_get_paramU  sE    ??3JJsO**2884::EBirE"I!A!s##iimSYYr]CIIbM!A!$$iimSYYr]CIIbM!Aq5FF5M	rA**E2X=J66"))"3"3Y"?@L%
(A BCDG%
(A BCDG|w|!!#&&=Q,ABII		A ((ii@D$OA=		((w.C(DsJAdA6A))##Aq{Q7C99$$Qa8Dg11- 0 !Q3r0   c                l  ^^^^^^^^^^ TR                   S   TR                   S   TR                   S   snmmTT-  m[        R                  " [        R                  " U5      5      mUU4S jnUUU4S jn[        R
                  " T/5      R                  S5      m[        R
                  " T/5      R                  S5      mTR                  5       TR                  5       smm[        R                  " S/SSS	9n[        R                  " S/S
SS	9n	[        R                  R                  R                  XgXTT/5      u  pmmUc1  [        R                  " UTT/S9R                  TR                  5      mO
USS2SS4   m[        R                  " S/5      R                  S5      m[        R                  R                  R                  [        R                   " TT:  TT:  5      UU4S jU4S j5      n
[        R                  R                  R                  [        R                   " TT:  TT:  5      UU4S jU4S j5      n[        R                  R                  R                  [        R                   " TT:  TT:  5      U4S jU4S j5      m[        R                  R                  R                  [        R                   " TT:  TT:  5      U4S jU4S j5      m[        R                  R                  R                  [        R                   " TT:  TT:  5      U4S jU4S j5      mXTTTU4$ )a  Get parameters for ``erase`` for a random erasing in static mode.

Args:
    img (paddle.static.Variable): Image to be erased.
    scale (sequence, optional): The proportional range of the erased area to the input image.
    ratio (sequence, optional): Aspect ratio range of the erased area.
    value (sequence | None): The value each pixel in erased area will be replaced with.
                       If value is a sequence with length 3, the R, G, B channels will be erased
                       respectively. If value is None, each pixel will be erased with random values.

Returns:
    tuple: params (i, j, h, w, v) to be passed to ``erase`` for random erase.
r*  r+  rA   c                l   > [         R                  " X:  [         R                  " UT:  UT:  5      5      $ r'   r   )r   r   r3  r4  r   r   s       r,   r   -RandomErasing._static_get_param.<locals>.cond  s7    %%!!qLaK r0   c                  > [         R                  " S/TS   TS   S9T-  n[         R                  " [         R                  " S/TS   TS   S95      n[         R                  " [         R                  " XE-  5      5      R                  S5      n[         R                  " [         R                  " XE-  5      5      R                  S5      nU S-  n XX#/$ )Nr   r   )r   rW   r   )r   r   r   r   r   cast)	r   r   r3  r4  r2  r   r1  r   r   s	         r,   r  -RandomErasing._static_get_param.<locals>.body  s    saeAh?(J  "::s	!)A,GL ll6;;z/H#IJOOG ll6;;z/H#IJOOG qLG'33r0   r   r   r   r   r   NrJ  c                 \   > [         R                  " S/STT -
  S-   S9R                  S5      $ r  r  )r3  r   s   r,   r  1RandomErasing._static_get_param.<locals>.<lambda>  -    FNNcqa'kAofWor0   c                    > T $ r'   r(   zeros   r,   r  r@        Dr0   c                 \   > [         R                  " S/STT -
  S-   S9R                  S5      $ r  r  )r4  r   s   r,   r  r@    rA  r0   c                    > T $ r'   r(   rC  s   r,   r  r@    rE  r0   c                    > T $ r'   r(   )r3  s   r,   r  r@        Gr0   c                    > T $ r'   r(   )r   s   r,   r  r@        Ar0   c                    > T $ r'   r(   )r4  s   r,   r  r@    rI  r0   c                    > T $ r'   r(   )r   s   r,   r  r@    rK  r0   c                    > T $ r'   r(   )r5  s   r,   r  r@    s    !r0   c                    > T $ r'   r(   rN   s   r,   r  r@    s    Sr0   )rH   r   r   r/  r   r  r  cloner   r  r  r#  r.  r   r!  r   r   )r*   rO   r   r   rZ   r0  r   r  r   r   r6  r7  r3  r4  r   r1  r   r5  r   rD  s    ``         @@@@@@@@r,   r$  RandomErasing._static_get_param  s    ))B-2		"1aq5FF288E?+			4$ MM1#%%g.MM1#%%g.779aggi++#!7
 kk#"G
 *0)9)9)D)Dw8*
&gw =Q$9:AA#))LAatm$A||QC ''0mm##w{GaK8 
 }}$$w{GaK8 
 --""''w{GaK8
 --""''w{GaK8
 MM!!w{GaK8)[
 '7Aw66r0   c           	     
   [         R                   " 5       U R                  :  a  [        U R                  [        R
                  5      (       a  U R                  /nO.[        U R                  [        5      (       a  SnOU R                  nUb)  [        U5      S:X  d  [        U5      S:X  d  [        S5      eU R                  XR                  U R                  U5      u  p4pVn[        R                  " XXEXgU R                  5      $ U$ )z
Args:
    img (paddle.Tensor | np.array | PIL.Image): Image to be Erased.

Returns:
    output (paddle.Tensor | np.array | PIL.Image): A random erased image.
Nr   rB   TValue should be a single number or a sequence with length equals to image's channel.)r   r6  rT   rZ   rU   rV   r}   rJ   rK   r   r   r   rD   eraser&  )r*   rO   rZ   r6  r7  r3  r4  r5  s           r,   r@  "RandomErasing._dynamic_apply_image  s     ==?TYY&$**gnn55DJJ,,

 #e*/SZ1_ j  .2-D-DZZU.*Cw 773TGMM
r0   c           	        [        U R                  [        R                  5      (       a;  [        R
                  " U R                  /5      R                  UR                  5      nO[[        U R                  [        5      (       a  SnO9[        R
                  " U R                  5      R                  UR                  5      nUb1  UR                  S   S:X  d  UR                  S   S:X  d  [        S5      eU R                  XR                  U R                  U5      u  p4pVpx[        R                  " XXEXgU R                   5      $ )z
Args:
    img (paddle.static.Variable): Image to be Erased.

Returns:
    output (paddle.static.Variable): A random erased image.
Nr   r   rB   rS  )rT   rZ   rU   rV   r   r  r  r   r}   rH   rK   r$  r   r   rD   rT  r&  )	r*   rO   rZ   r6  r7  r3  r4  r5  r   s	            r,   rA  !RandomErasing._static_apply_image	  s     djj'..11MM4::,/66syyAE

C((EMM$**-44SYY?EKKNa5;;q>Q#6f  372H2HTZZ3
/7Q wwsDLLIIr0   c                  ^ ^ [         R                  " 5       (       a  T R                  T5      $ [         R                  R                  R                  [         R                  " S/5      T R                  :  UU 4S jU4S j5      $ )Nr   c                 &   > TR                  T 5      $ r'   )rA  )rO   r*   s   r,   r  ,RandomErasing._apply_image.<locals>.<lambda>&	  s    005r0   c                    > T $ r'   r(   rN   s   r,   r  rZ  '	  s    r0   )r   r'  r@  r  r  r   rQ  r6  r   s   ``r,   r   RandomErasing._apply_image 	  s]    !!##,,S11==##((QC 499,5 r0   )r&  r6  r   r   rZ   )rV  )g{Gz?gQ?)g333333?gffffff
@r   FN)r6  r   r   r   r   r   rZ   zfloat | Sequence[float] | strr&  rl  r   r   r5   r|   )r:   r;   r<   r=   r~   r   rg   r   r$  r@  rA  r   r>   r   r   s   @r,   r%  r%    s    )V K..M !-!+/0+/## # 	#
 -# # )# 
# #J0db7H4J6 r0   r%  )r  )H
__future__r   r   rU   r   rn   collections.abcr   r   typingr   r   r   r	   r
   r   r   numpyr   typing_extensionsr   r    r   rD   numpy.typingnpt	PIL.Imager   r   r   paddle._typingr   r   r   r   r   r   r   r   r   r   r!   r$   __all__rP   r   r_   ra   r   r   r   r   r-  r5  r[  ri  rv  r  r  r  r  r  r  r  r  r  r  r   r
  r  r%  r(   r0   r,   <module>rh     s   #     .    '  +CC%-23&   x%7t 	Xz#5	
)77E>2 ) 8& !U5\!2t0:j%( :zh"Jw~. h"VA2}Wh./ A2HD<]7E>* D<N_Dgun5 _DD*-w~. *-Z<
=%8 <
~<
w~6 <
~G
gun- G
T5)gun- 5)p0;-7 0;f.7gun5 .7b+;-7 +;\.-=%0 .-b_-/ _DC'w~. C'LTF-
' TFn	H
!y
=%0 y
xi
]7E>2 i
XLgun5 L^1=gun- 1=hjM'5.1 jr0   