+
    úäûjÃ$  ã                   ó�   € ^ RI t ^ RIHtHtHtHtHtHt ^ RIt^ RI	H
t ^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHt  ! R R	]4      tR# )
é    N)ÚAnyÚDictÚListÚOptionalÚTupleÚUnion)Úrandom_generator)ÚMixAugmentationBaseV2)ÚDataKeyÚDType)Ú_to_device_nonblocking)Úbbox_to_maskÚinfer_bbox_shapec                   ó„   a a€ ] tR t^t oRtRV3R lV 3R llltV3R lR ltRV3R lR lltRV3R lR	 lltR
t	Vt
V ;t# )ÚRandomCutMixV2a¾  Mix rectangular image regions and labels, applied to a batch with probability ``p`` (default 1.0).

``images, labels = RandomCutMixV2(data_keys=["input", "class"])(input, label)`` mixes image patches and
returns label pairs with their coefficients. Use :class:`RandomMixUpV2` to blend complete images instead.

Args:
    p: probability for applying an augmentation to a batch. This param controls the augmentation
               probabilities batch-wisely.
    num_mix: cut mix times.
    beta: hyperparameter for generating cut size from beta distribution.
        Beta cannot be set to 0 after torch 1.8.0. If None, it will be set to 1.
    cut_size: the ``[min, max]`` clamp, within [0, 1], applied to the Beta-sampled mixing coefficient
        ``lambda``, not the fraction of the image to cut. The cut side is ``floor(sqrt(1 - lambda) * side)``,
        so a larger ``cut_size`` gives a *smaller* cut, and a minimum of 1 is rejected because it would cut
        nothing. If None, it will be set to [0, 1], which means no restriction.
    same_on_batch: apply the same transformation across the batch.
        This flag will not maintain permutation order.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
                    to the batch form (False).
    data_keys: list of keys to apply the mix augmentation to.
    use_correct_lambda: if True, compute lambda according to the CutMix paper
        (`lam = 1 - area_ratio`). Defaults to False (`lam = area_ratio`) for backward compatibility,
        but will raise a deprecation warning when False.

Inputs:
    - Input image tensors, shape of ``(B, C, H, W)``.
    - Raw labels, shape of ``(B)``.

Returns:
    Tuple[torch.Tensor, torch.Tensor]:
    - Adjusted image, shape of ``(B, C, H, W)``.
    - Raw labels, permuted labels and lambdas for each mix, shape ``(num_mix, B, 3)``.

Convention:
    - With ``data_keys=["input", "class"]``, the class output is ``(num_mix, B, 3)``. Its last axis holds
      the original label, the label selected by that mix's permutation, and the area fraction returned as
      lambda. Labels must be one-dimensional and are returned as floating values in the image dtype, except that
      a ``float16`` or ``bfloat16`` image yields ``float32`` labels so integer class ids up to
      ``2 ** 24`` stay exact.
      ``use_correct_lambda=True`` returns ``1 - cut_area / image_area``;
      the compatibility default returns ``cut_area / image_area`` and emits a deprecation warning.
    - ``p`` is a batch-wide gate applied once, unlike the per-sample ``p`` of :class:`RandomJigsaw`:
      ``_params["batch_prob"]`` is all ones or all zeros,
      and every row and mix of a selected batch receives a cut, though self-pairing or a zero-sized cut can
      leave a row unchanged. With ``same_on_batch=False`` each row and mix draws its own cut size and placement;
      ``same_on_batch=True`` shares each mix's cut size and placement across rows; each mix still draws its own
      pairing and geometry. At ``p=0`` the image is unchanged and each class row contains the original label twice
      with lambda zero.

.. image:: _static/img/RandomCutMixV2.png

Implementation for `CutMix: Regularization Strategy to Train Strong Classifiers with
Localizable Features` :cite:`yun2019cutmix`.

The implementation referred to the following repository: `https://github.com/clovaai/CutMix-PyTorch
<https://github.com/clovaai/CutMix-PyTorch>`_.

See the Convention block on :class:`~kornia.augmentation.MixAugmentationBaseV2`.

See Also:
    - :class:`RandomMixUpV2`: blends complete paired images instead of rectangular patches.

Examples:
    >>> rng = torch.manual_seed(3)
    >>> input = torch.rand(2, 1, 3, 3)
    >>> input[0] = torch.ones((1, 3, 3))
    >>> label = torch.tensor([0, 1])
    >>> cutmix = RandomCutMixV2(data_keys=["input", "class"], use_correct_lambda=True)
    >>> cutmix(input, label)
    [tensor([[[[1.0000, 1.0000, 1.0000],
              [0.1498, 0.4015, 1.0000],
              [0.4594, 0.1756, 1.0000]]],
    <BLANKLINE>
    <BLANKLINE>
            [[[0.8879, 1.0000, 1.0000],
              [0.1498, 1.0000, 1.0000],
              [0.4594, 0.1756, 0.9492]]]]), tensor([[[0.0000, 1.0000, 0.5556],
             [1.0000, 0.0000, 0.5556]]])]

c                ó  <€ V ^8„  d   QhRS[ RS[S[S[P                  S[S[S[3,          3,          ,          RS[S[S[P                  S[3,          ,          RS[RS[RS[RS[S[S[S[	S[ S[
3,          ,          ,          RS[R	R
/	# )é   Únum_mixÚcut_sizeÚbetaÚsame_on_batchÚpÚkeepdimÚ	data_keysÚuse_correct_lambdaÚreturnN)Úintr   r   ÚtorchÚTensorr   ÚfloatÚboolr   Ústrr   )ÚformatÚ__classdict__s   "€Ú^C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\mix\cutmix.pyÚ__annotate__ÚRandomCutMixV2.__annotate__p   sª   ø€ ÷ ñ áðñ ™5¡§¡©u±U¹E°\Õ/BÐ!BÕCÕDðñ ‘u™UŸ\™\©5Ð0Õ1Õ2ð	ñ
 ðñ ðñ ðñ ™D¡¡s©C±Ð'8Õ!9Õ:Õ;ðñ !ðð 
ñó    c	                óÖ   <€ \         S	V `  R WTWgR7       \        P                  ! W#VR R7      V n        W€n        V P
                  '       g    \        P                  ! R\        ^R7       R# R# )ç      ð?)r   Úp_batchr   r   r   )r   z½RandomCutMixV2 currently uses the old (inconsistent) lambda computation. Set `use_correct_lambda=True` to align with the original CutMix paper. This default will change in a future release.)Ú
stacklevelN)	ÚsuperÚ__init__ÚrgÚCutmixGeneratorÚ_param_generatorr   ÚwarningsÚwarnÚDeprecationWarning)
Úselfr   r   r   r   r   r   r   r   Ú	__class__s
   &&&&&&&&&€r%   r.   ÚRandomCutMixV2.__init__p   sd   ø€ ô 	‰Ñ˜3¨ÐPWÐÔmÜ46×4FÒ4FÀxÐW^ÐbeÔ4fˆÔà"4ÔØ×&×&Ð&Ü�MŠMð@ô #Ø÷ñ 'r(   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# ©r   ÚinputÚparamsÚflagsr   )r   r   r   r"   r   )r#   r$   s   "€r%   r&   r'   ˆ   sN   ø€ ÷ *ñ *Ù—\‘\ð*Ù+/±±U·\±\Ð0AÕ+Bð*ÙKOÑPSÑUXÐPXÍ>ð*á	�‰ñ*r(   c                óT  € VR ,          w  rE. p\         P                  ! \        VR,          P                  4       4      4      pV\        P
                  \        P                  39   d   TM\        P
                  p\        VR,          VR,          4       Fü  w  ršVP                  ^ \        W‘P                  4      R7      p\        V
4      w  rÍVP                  V4      VP                  V4      ,          WT,          ,          pV P                  '       d
   ^V,
          MTpVP                  \        P                  ! VP                  VP                  VR7      VP                  VP                  VR7      \        WñP                  V4      .^4      4       Kþ  	  \        P                  ! V^ 4      # )Úimage_shapeÚdtypeÚ	mix_pairsÚcrop_src©ÚdimÚindex©Údevicer?   )r   Úto_torchr   Úitemr   Úfloat32Úfloat64ÚzipÚindex_selectr   rF   r   Útor   ÚappendÚstack)r5   r:   r;   r<   ÚheightÚwidthÚ
out_labelsÚimage_dtypeÚ
calc_dtypeÚpairÚcropÚlabels_permuteÚwÚhÚlam_valÚlams   &&&&            r%   Úapply_transform_classÚ$RandomCutMixV2.apply_transform_classˆ   sL  € ð ˜}Õ-‰ˆàˆ
Ü—n’n¤S¨°­×)=Ñ)=Ó)?Ó%@ÓAˆØ$/´E·M±MÄ5Ç=Á=Ð3QÔ$Q‘[ÔW\×WdÑWdˆ
Ü˜f [Õ1°6¸*Õ3EÖF‰JˆDØ"×/Ñ/°AÔ=SÐTX×ZfÑZfÓ=gÐ/ÓhˆNÜ# DÓ)‰DˆAà—d‘d˜:Ó&¨¯©¨jÓ)9Õ9¸U½^ÕLˆGØ!%×!8×!8Ð!8�!�g–+¸gˆCà×ÑÜ—’àŸ™¨¯©¸J˜ÓGØ&×)Ñ)°·±ÀZÐ)ÓPÜ.¨s·L±LÀ*ÓMðð
 óö	ñ Gô$ �{Š{˜: qÓ)Ð)r(   c          	      óª   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[S[3,          ,          RS[ P                  /# r9   ©r   r   r   r"   r   r   )r#   r$   s   "€r%   r&   r'   ¤   sU   ø€ ÷ *ñ *Ù—\‘\ð*Ù+/±±U·\±\Ð0AÕ+Bð*ÙKSÑTXÑY\Ñ^aÐYaÕTbÕKcð*á	�‰ñ*r(   c                ól  € . p\         P                  ! \        VR ,          P                  4       4      4      pV\        P
                  \        P                  39   d   TM\        P
                  p\        P                  ! \        V4      VP                  VR7      p\        V P                  P                  4       Fb  pVP                  \        P                  ! VP                  VP                  VR7      VP                  VP                  VR7      V.^4      4       Kd  	  \        P                  ! V^ 4      # )r?   rE   )r   rG   r   rH   r   rI   rJ   ÚzerosÚlenrF   Úranger1   r   rN   rO   rM   )	r5   r:   r;   r<   rR   rS   rT   r[   Ú_s	   &&&&     r%   Úapply_non_transform_classÚ(RandomCutMixV2.apply_non_transform_class¤   sâ   € ð ˆ
Ü—n’n¤S¨°­×)=Ñ)=Ó)?Ó%@ÓAˆØ$/´E·M±MÄ5Ç=Á=Ð3QÔ$Q‘[ÔW\×WdÑWdˆ
Ü�kŠkœ3˜u›:¨u¯|©|À:ÔNˆÜ�t×,Ñ,×4Ñ4Ö5ˆAØ×ÑÜ—’àŸ™¨¯©¸J˜ÓGØŸ™¨¯©¸J˜ÓGØðð
 óö	ñ 6ô �{Š{˜: qÓ)Ð)r(   c          	      óª   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[S[3,          ,          RS[ P                  /# )r   r:   r;   Úmaybe_flagsr   r_   )r#   r$   s   "€r%   r&   r'   ¹   sU   ø€ ÷ ñ Ù—\‘\ðÙ+/±±U·\±\Ð0AÕ+BðÙQYÑZ^Ñ_bÑdgÐ_gÕZhÕQiðá	�‰ñr(   c                ó¨  € VP                  ^4      VP                  ^4      rTVP                  4       p\        VR,          VR,          4       F‚  w  rxVP                  ^ \	        WqP
                  4      R7      p	\        W„V3R7      P                  4       P                  ^R7      P                  ^VP                  ^4      ^^4      p
Wš,          Wj&   K„  	  V# )r   r@   rA   rB   )Úsize)rC   )
rj   ÚclonerK   rL   r   rF   r   r!   Ú	unsqueezeÚrepeat)r5   r:   r;   rh   rP   rQ   Ú
out_inputsrU   rV   Úinput_permuteÚmasks   &&&&       r%   Úapply_transformÚRandomCutMixV2.apply_transform¹   sÀ   € ð Ÿ
™
 1› u§z¡z°!£}�à—[‘[“]ˆ
Ü˜f [Õ1°6¸*Õ3EÖF‰JˆDØ!×.Ñ.°1Ô<RÐSW×YeÑYeÓ<fÐ.ÓgˆMä °E¨?Ô;×@Ñ@ÓB×LÑLÐQRÐLÓS×ZÑZÐ[\Ð^c×^hÑ^hÐijÓ^kÐmnÐpqÓrˆDØ,Õ2ˆJÓñ	 Gð Ðr(   )r1   r   )é   NNFr*   FNF)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r.   r\   re   rq   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r6   r$   s   @@r%   r   r      s9   ù‡ € ñO÷bõ ÷0*ð *÷8*ò *÷*÷ ò r(   r   )r2   Útypingr   r   r   r   r   r   r   Úkornia.augmentationr	   r/   Ú kornia.augmentation._2d.mix.baser
   Úkornia.constantsr   r   Úkornia.core.utilsr   Úkornia.geometry.bboxr   r   r   © r(   r%   Ú<module>rƒ      s1   ðó$ ß :× :ã å 6Ý Bß +Ý 4ß ?ôgÐ*ö gr(   