
    3jX                     r   S SK Jr  S SKJrJrJrJrJrJr  S SK	r	S SK	J
r
  S SKJrJrJr  S SKJr  S SKJrJrJrJr  S SKJr  S S	KJr  S S
KJr  \\	R8                  \\	R8                  \	R8                  4   4   rS\
R<                  S\S\	R8                  4S jr " S S\
R<                  5      r  " S S\ 5      r!g)    )Enum)AnyCallableDictOptionalTupleUnionN)nn)	BernoulliDistributionRelaxedBernoulli)RandomGeneratorBase)_adapted_rsampling_adapted_sampling_transform_output_shapeoverride_parameters)is_autocast_enabled)Boxes)	Keypointsselfinputreturnc                 F    [        S[        U 5      R                   S35      e)zYDefine the computation performed at every call.

Should be overridden by all subclasses.
znn.Module [z3] is missing the required "apply_tranform" function)NotImplementedErrortype__name__r   r   s     R/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/augmentation/base.py_apply_transform_unimplementedr   +   s$    
 DJ,?,?+@@st
uu    c                     ^  \ rS rSr% SrSr    S)S\S\S\S\SS	4
U 4S
 jjjr\	r
\S\R                  4   \S'   S\S\SS 4U 4S jjrS\4S jrS\R                  S\R                  4S jrS	SS.S\R                  S\\R                     S\S\R                  4S jjrS\R                  SS	4S jrS\R                  S\\S4   S\R                  4S jrS\\S4   S\\\R                  4   4S jrS\R8                  S\R:                  SS	4S  jrS\\S4   S\S\S\S\R                  4
S! jr  S*S"\\\\R                  4      S#\\\\4      S\S\\\\R                  4   \\\4   4   4S$ jjr S\\S4   S\\\R                  4   4S% jr!S\R                  S"\\\R                  4   S#\\\4   S\R                  4S& jr" S+S\R                  S"\\\\R                  4      S\S\R                  4S' jjr#S(r$U =r%$ ),_BasicAugmentationBase3   a  _BasicAugmentationBase base class for customized augmentation implementations.

Plain augmentation base class without the functionality of transformation matrix calculations.
By default, the random computations will be happened on CPU with ``torch.get_default_dtype()``.
To change this behaviour, please use ``set_rng_device_and_dtype``.

For automatically generating the corresponding ``__repr__`` with full customized parameters, you may need to
implement ``_param_generator`` by inheriting ``RandomGeneratorBase`` for generating random parameters and
put all static parameters inside ``self.flags``. You may take the advantage of ``PlainUniformGenerator`` to
generate simple uniform parameters with less boilerplate code.

Args:
    p: probability for applying an augmentation. This param controls the augmentation probabilities element-wise.
    p_batch: probability for applying an augmentation to a batch. This param controls the augmentation
      probabilities batch-wise.
    same_on_batch: apply the same transformation across the batch.
    keepdim: whether to keep the output shape the same as input ``True`` or broadcast it to
      the batch form ``False``.

Fpp_batchsame_on_batchkeepdimr   Nc                 v  > [         TU ]  5         Xl        X l        X0l        X@l        0 U l        U   U   US;  a  [        U R                  5      U l        US;  a  [        U R                  5      U l	        S U l
        0 U l        U R                  [        R                  " S5      [        R                  " 5       5        g )N>                 ?cpu)super__init__r$   r%   r&   r'   _paramsr   _p_gen_p_batch_gen_param_generatorflagsset_rng_device_and_dtypetorchdeviceget_default_dtype)r   r$   r%   r&   r'   	__class__s        r   r-   _BasicAugmentationBase.__init__M   s     	*02J#DFF+DK*$ )$,, 7D?C%'
%%ell5&95;R;R;TUr    .apply_transformargskwargsc                    > [         R                  R                  R                  " U0 UD6u  p4  nU R	                  X45        [
        TU ]  " U0 UD6$ )z9Set the device and dtype for the random number generator.)r4   _C_nn	_parse_tor3   r,   to)r   r:   r;   r5   dtype_r7   s         r   r@   _BasicAugmentationBase.tof   sI    #hhll44dEfEq!%%f4wz4*6**r    c                    SU R                    SU R                   SU R                   3n[        U R                  [
        5      (       a  U R                  < SU 3nU R                  R                  5        HJ  u  p#[        U[        5      (       a%  USU SUR                  R                  5        3-  nM?  USU SU 3-  nML     U R                  R                   SU S3$ )Nzp=z
, p_batch=z, same_on_batch=z, =())r$   r%   r&   
isinstancer1   r   r2   itemsr   namelowerr7   r   )r   txtkvs       r   __repr___BasicAugmentationBase.__repr__l   s    466(*T\\N2B4CUCUBVWd++-@AA**-Ru5CJJ$$&DA!T""A3a/00A3as|#	 '
 ..))*!C522r    r   c                     U$ N r   s     r   __unpack_input__'_BasicAugmentationBase.__unpack_input__w   s    r    Tshapematch_channelrW   rX   c                    [         e)zStandardize input tensors.r   )r   r   rW   rX   s       r   transform_tensor'_BasicAugmentationBase.transform_tensorz   
     "!r    c                     [         e)z9Check if the input torch.Tensor is formatted as expected.rZ   r   s     r   validate_tensor&_BasicAugmentationBase.validate_tensor   s    !!r    outputoutput_shapec                 >    U R                   (       a  [        X5      $ U$ )zStandardize output tensors.)r'   r   )r   ra   rb   s      r   transform_output_tensor._BasicAugmentationBase.transform_output_tensor   s    @D&v<XRXXr    batch_shapec                 V    U R                   b  U R                  XR                  5      $ 0 $ rR   )r1   r&   )r   rf   s     r   generate_parameters*_BasicAugmentationBase.generate_parameters   s*      ,((6H6HII	r    r5   rA   c                 n    Xl         X l        U R                  b  U R                  R                  X5        gg)zChange the random generation device and dtype.

Note:
    The generated random numbers are not reproducible across different devices and dtypes.

N)r5   rA   r1   r3   )r   r5   rA   s      r   r3   /_BasicAugmentationBase.set_rng_device_and_dtype   s3     
  ,!!::6I -r    c                    US:X  a  [         R                  " S5      S-   nOlUS:X  a  [         R                  " S5      nOO[        U R                  [        45      (       a  [        SU R                  U5      nO[        SU R                  U5      nUR                  5       S:X  a  US:X  a  [         R                  " US   5      S-   nOwUS:X  a  [         R                  " US   5      nOW[        U R                  [        45      (       a  [        US   4U R                  U5      nO[        US   4U R                  U5      nXV-  nOUR                  US   5      n[        UR                  5      S:X  a  US   $ U$ )N   r   )rm      ).r   )r4   zerosrH   r0   r   r   r   sumr/   repeatlenrW   )r   rf   r$   r%   r&   
batch_prob	elem_probs          r   __batch_prob_generator__/_BasicAugmentationBase.__batch_prob_generator__   s=    a<Q!+J\QJ)),<+>??+D$2C2C]SJ*41B1BMRJ>>q Av!KKA7!;	a!KKA7	DKK*:)<==.A/@$++}]	-{1~.?m\	#/J#**;q>:Jz A%f%%r    paramsr2   c                     SU;   a  US   OSnUc  U R                   OUnUc  U R                  OUnU(       a  [        XSS9nXl         OXl         [        XSS9n[        X#SS9nX4$ )Nsave_kwargsFT)in_place)r.   r2   r   )r   rw   r2   r;   ry   s        r   #_process_kwargs_to_params_and_flags:_BasicAugmentationBase._process_kwargs_to_params_and_flags   sn     0=/Ff]+E!'V#m

($GF!L!L(%HF#EEB}r    c                    U R                  XR                  U R                  U R                  5      nUS:  nU R	                  [
        R                  " [        UR                  5       R                  5       5      /USS  Q75      5      nUc  0 nX$S'   [
        R                  " U[
        R                  S9nUR                  SU05        U$ )N      ?rm   rs   )rA   forward_input_shape)ru   r$   r%   r&   rh   r4   Sizeintrp   itemtensorlongupdate)r   rf   rs   to_applyr.   
input_sizes         r   forward_parameters)_BasicAugmentationBase.forward_parameters   s    22;VZVhVhi
#**5::s8<<>;N;N;P7Q6dT_`a`bTc6d+ef?G * \\+UZZ@
-z:;r    c                 &    U R                  XU5      $ rR   )r9   )r   r   rw   r2   s       r   
apply_func!_BasicAugmentationBase.apply_func   s    ##E599r    c                    U R                  U5      nUR                  nU R                  U5      nUR                  nUc  U R                  U5      nSU;  a   [        R
                  " S/US   -  5      US'   U R                  " X R                  40 UD6u  p'U R                  XBU5      nU R                  (       a  U R                  X5      $ U$ )a  Perform forward operations.

Args:
    input: the input torch.Tensor.
    params: the corresponding parameters for an operation.
        If None, a new parameter suite will be generated.
    **kwargs: key-value pairs to override the parameters and flags.

Note:
    By default, all the overwriting parameters in kwargs will not be recorded
    as in ``self._params``. If you wish it to be recorded, you may pass
    ``save_kwargs=True`` additionally.

rs   Tr   )rT   rW   r[   r   r4   r   r{   r2   r   r'   rd   )	r   r   rw   r;   	in_tensorinput_shaperf   r2   ra   s	            r   forward_BasicAugmentationBase.forward   s    " ))%0	oo)))4	oo>,,[9Fv%#(<<Q0G#HF< @@^W]^E:DHLLt++F@\V\\r    )r0   r/   r1   r.   r5   rA   r2   r'   r$   r%   r&   )r~   r*   FF)NNrR   )&r   
__module____qualname____firstlineno____doc__ONNX_EXPORTABLEfloatboolr-   r   r9   r   r4   Tensor__annotations__r   r@   strrO   rT   r   r[   r_   r   r   rd   r   rh   r5   rA   r3   ru   r{   r   r   r   __static_attributes____classcell__)r7   s   @r   r"   r"   3   s   . O #VV V 	V
 V 
V V. 4ROXc5<</0Q+ +s +/G +	3# 	3ell u||  )-""||" %	"
 " 
""U\\ "d "Yell Y%PSUXPX/ Y^c^j^j YuS#X 4U\\HYCZ 

Ju|| 
JEKK 
JTX 
J!38_! ! 	!
 ! 
!J 59*.c5<</01 S#X' 	
 
tC%&S#X6	7,eCHo $sELLGXBY : :d3;L6M :VZ[^`c[cVd :iniuiu : PT]\\]+3Dell9J4K+L]_b]	] ]r    r"   c                      \ rS rSrSr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S	 jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S
 jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\	S\R                  4S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\	S\R                  4S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\	S\4S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\	S\4S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\	S\R                  4S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\4
S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\4
S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\4
S jjr SS\S\\\R                  4   S\\\	4   S\
\R                     S\4
S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S jjr SS\R                  S\\\R                  4   S\\\	4   S\
\R                     S\R                  4
S jjr SS\R                  S\\\R                  4   S\
\\\	4      S\R                  4S jjrSrg)_AugmentationBasei  a|  _AugmentationBase base class for customized augmentation implementations.

Advanced augmentation base class with the functionality of transformation matrix calculations.

Args:
    p: probability for applying an augmentation. This param controls the augmentation probabilities
      element-wise for a batch.
    p_batch: probability for applying an augmentation to a batch. This param controls the augmentation
      probabilities batch-wise.
    same_on_batch: apply the same transformation across the batch.
    keepdim: whether to keep the output shape the same as input ``True`` or broadcast it
      to the batch form ``False``.

Nr   rw   r2   	transformr   c                     [         erR   rZ   r   r   rw   r2   r   s        r   r9   !_AugmentationBase.apply_transform  r]   r    c                     U$ rR   rS   r   s        r   apply_non_transform%_AugmentationBase.apply_non_transform!  s	     r    r;   c                    U R                   " Uc  U R                  OUU40 UD6u  p#US   nUS:  nUR                  nU R                  U5      n	U R	                  U	5        UR                  5       (       a  U R                  XX4S9n
OUR                  5       (       d  U R                  XX4S9n
OU R                  XX4S9n
U R                  X   UUUc  UOXG   S9n[        5       (       a6  U
R                  UR                  5      n
UR                  UR                  5      nU
R                  U4U5      n
U R                  (       a  [        X5      OU
n
[        5       (       a  U
R                  UR                  5      n
U
$ Nrs   r~   r   )r{   r.   rW   r[   r_   allr9   anyr   r   r   rA   	index_putr'   r   )r   r   rw   r2   r   r;   rs   r   	ori_shaper   ra   applieds               r   transform_inputs"_AugmentationBase.transform_inputs,  sd    @@"NDLL
AG
 L)
#KK	))%0	Y'<<>>)))U)XF--i-\F--i-\F**#'0'8)i>Q	 + G #$$U[[1!,,u{{3%%xk7;F?C||(;QW  [[-Fr    c                    U R                   " Uc  U R                  OUU40 UD6u  p#US   nUS:  nUR                  nUS   n	U R                  XSS9n
U R	                  U
5        UR                  5       (       a  U R                  XX4S9nOdUR                  5       (       d  U R                  XX4S9nO>U R                  XX4S9nU R                  X   UUUc  UOXG   S9nUR                  U4U5      nU R                  (       a  [        XU	S9nU$ UnU$ )Nrs   r~   r   FrV   r   )reference_shape)r{   r.   rW   r[   r_   r   apply_transform_maskr   apply_non_transform_maskr   r'   r   )r   r   rw   r2   r   r;   rs   r   r   rW   r   ra   r   s                r   transform_masks!_AugmentationBase.transform_masksV  s;    @@"NDLL
AG
 L)
#KK	,-))%E)R	Y'<<>>..y%.]F229e2aF229e2aF//#'0'8)i>Q	 0 G %%xk7;FVZVbVb(ER ior    c                 |   [        U[        5      (       d  [        S[        U5       S35      eU R                  " Uc  U R
                  OUU40 UD6u  p#US   nUS:  nUR                  5       R                  5       (       a  U R                  XX4S9nU$ UR                  5       (       d  U R                  XX4S9nU$ U R                  XX4S9nU R                  X   UUUc  UOXG   S9n	[        5       (       a6  UR                  UR                  5      nU	R                  UR                  5      n	UR                  U4U	5      nU$ )NzOnly `Boxes` is supported. Got .rs   r~   r   )rH   r   RuntimeErrorr   r{   r.   r   r   apply_transform_boxr   apply_non_transform_boxr   rA   r   
r   r   rw   r2   r   r;   rs   r   ra   r   s
             r   transform_boxes!_AugmentationBase.transform_boxesz  sO    %''!@eQOPP@@"NDLL
AG
 L)
#==?  --eU-XF   11%1\F  11%1\F..'0'8)i>Q	 / G #$$U[[1!,,u{{3%%xk7;Fr    c                 `   [        U[        5      (       d  [        S[        U5       S35      eU R                  " Uc  U R
                  OUU40 UD6u  p#US   nUS:  nUR                  5       (       a  U R                  XX4S9nU$ UR                  5       (       d  U R                  XX4S9nU$ U R                  XX4S9nU R                  X   UUUc  UOXG   S9n	[        5       (       a6  UR                  UR                  5      nU	R                  UR                  5      n	UR                  U4U	5      nU$ )Nz#Only `Keypoints` is supported. Got r   rs   r~   r   )rH   r   r   r   r{   r.   r   apply_transform_keypointr   apply_non_transform_keypointr   rA   r   r   s
             r   transform_keypoints%_AugmentationBase.transform_keypoints  sF    %++!DT%[MQRSTT@@"NDLL
AG
 L)
#<<>>225%2]F  66ue6aF  66ue6aF33'0'8)i>Q	 4 G #$$U[[1!,,u{{3%%xk7;Fr    c                 |   U R                   " Uc  U R                  OUU40 UD6u  p#US   nUS:  nUR                  5       (       a  U R                  XX4S9nU$ UR	                  5       (       d  U R                  XX4S9nU$ U R                  XX4S9nU R                  X   UUUc  UOXG   S9n	UR                  U4U	5      nU$ r   )r{   r.   r   apply_transform_classr   apply_non_transform_classr   r   s
             r   transform_classes#_AugmentationBase.transform_classes  s     @@"NDLL
AG
 L)
#<<>>//u/ZF  33E53^F  33E53^F00'0'8)i>Q	 1 G %%xk7;Fr    c                     [         e)zMProcess masks corresponding to the inputs that are no transformation applied.rZ   r   s        r   r   *_AugmentationBase.apply_non_transform_mask  r]   r    c                     [         e)z?Process masks corresponding to the inputs that are transformed.rZ   r   s        r   r   &_AugmentationBase.apply_transform_mask  r]   r    c                     U$ )zMProcess boxes corresponding to the inputs that are no transformation applied.rS   r   s        r   r   )_AugmentationBase.apply_non_transform_box  	     r    c                     [         e)z?Process boxes corresponding to the inputs that are transformed.rZ   r   s        r   r   %_AugmentationBase.apply_transform_box  r]   r    c                     U$ )zQProcess keypoints corresponding to the inputs that are no transformation applied.rS   r   s        r   r   ._AugmentationBase.apply_non_transform_keypoint  r   r    c                     [         e)zCProcess keypoints corresponding to the inputs that are transformed.rZ   r   s        r   r   *_AugmentationBase.apply_transform_keypoint  r]   r    c                     U$ )zRProcess class tags corresponding to the inputs that are no transformation applied.rS   r   s        r   r   +_AugmentationBase.apply_non_transform_class  r   r    c                     [         e)zDProcess class tags corresponding to the inputs that are transformed.rZ   r   s        r   r   '_AugmentationBase.apply_transform_class%  r]   r    r   c                 H    Uc  U R                   nU R                  XU5      nU$ rR   )r2   r   )r   r   rw   r2   ra   s        r   r   _AugmentationBase.apply_func/  s)     =JJE&&y%@r    rS   rR   )r   r   r   r   r   r4   r   r   r   r   r   r9   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   r    r   r   r     s   ( -1"||" S%,,&'" CH~	"
 ELL)" 
" -1	||	 S%,,&'	 CH~		
 ELL)	 
	  -1(||( S%,,&'( CH~	(
 ELL)( ( 
(^ -1"||" S%,,&'" CH~	"
 ELL)" " 
"R -1## S%,,&'# CH~	#
 ELL)# # 
#T -1!! S%,,&'! CH~	!
 ELL)! ! 
!P -1|| S%,,&' CH~	
 ELL)  
D -1"||" S%,,&'" CH~	"
 ELL)" 
" -1"||" S%,,&'" CH~	"
 ELL)" 
" -1 S%,,&' CH~	
 ELL) 
 -1"" S%,,&'" CH~	"
 ELL)" 
" -1 S%,,&' CH~	
 ELL) 
 -1"" S%,,&'" CH~	"
 ELL)" 
" -1|| S%,,&' CH~	
 ELL) 
 -1"||" S%,,&'" CH~	"
 ELL)" 
" +/	<< S%,,&' S#X'	
 
 r    r   )"enumr   typingr   r   r   r   r   r	   r4   r
   torch.distributionsr   r   r   $kornia.augmentation.random_generatorr   kornia.augmentation.utilsr   r   r   r   kornia.core.utilsr   kornia.geometry.boxesr   kornia.geometry.keypointsr   r   TensorWithTransformMatModuler   r"   r   rS   r    r   <module>r      s   $  > >   I I D  2 ' /u||U5<<3M-NNO v vC vELL vQ]RYY Q]hs. sr    