+
    úäûj  ã                   óx   € ^ 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 R]4      tR# )	é    )ÚAnyÚDictÚListÚOptionalÚTupleÚUnionN)Úrandom_generator)ÚMixAugmentationBaseV2)ÚDataKeyÚDType)Ú_to_device_nonblockingc                   óˆ   a a€ ] tR t^t oRtRV3R lV 3R llltRV3R lR l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# )ÚRandomMixUpV2ag  Mix pairs of images and labels, applied to a batch with probability ``p`` (default 1.0).

``images, labels = RandomMixUpV2(data_keys=["input", "class"])(input, label)`` returns blended images and
paired labels with mixing coefficients. Use :class:`RandomCutMixV2` to replace a rectangular region instead.

Args:
    p: probability for applying an augmentation to a batch. This param controls the augmentation
               probabilities batch-wisely.
    lambda_val: min-max value of mixup strength. Default is 0-1.
    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).

Inputs:
    - Input image tensors, shape of ``(B, C, H, W)``.
    - Label: 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 of ``(B, 3)``.

Convention:
    - With ``data_keys=["input", "class"]``, the class output is ``(B, 3)``: its columns are the original
      label, the label selected by ``_params["mixup_pairs"]``, and the sampled lambda. The image is
      ``input * (1 - lambda) + paired_input * 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.
    - ``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 of a selected batch draws its lambda from ``lambda_val``. At ``p=0`` the image is unchanged
      and the class output holds the original label twice with a zero lambda. ``same_on_batch=True`` shares
      the lambda draw but not the pairing, which may pair a sample with itself.

.. image:: _static/img/RandomMixUpV2.png

Implementation for `mixup: BEYOND EMPIRICAL RISK MINIMIZATION` :cite:`zhang2018mixup`.

The implementation is on top of the following repository:
`https://github.com/hongyi-zhang/mixup/blob/master/cifar/utils.py
<https://github.com/hongyi-zhang/mixup/blob/master/cifar/utils.py>`_.

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

See Also:
    - :class:`RandomCutMixV2`: mixes paired images through sampled rectangular regions.

Examples:
    The loss and accuracy can use the returned original label, paired label and lambda:

    .. code-block:: python

        def loss_mixup(y, logits):
            criterion = F.cross_entropy
            loss_a = criterion(logits, y[:, 0].long(), reduction='none')
            loss_b = criterion(logits, y[:, 1].long(), reduction='none')
            return ((1 - y[:, 2]) * loss_a + y[:, 2] * loss_b).mean()

        def acc_mixup(y, logits):
            pred = torch.argmax(logits, dim=1).to(y.device)
            return (1 - y[:, 2]) * pred.eq(y[:, 0]).float() + y[:, 2] * pred.eq(y[:, 1]).float()

    >>> rng = torch.manual_seed(1)
    >>> input = torch.rand(2, 1, 3, 3)
    >>> label = torch.tensor([0, 1])
    >>> mixup = RandomMixUpV2(data_keys=["input", "class"])
    >>> mixup(input, label)
    [tensor([[[[0.7576, 0.2793, 0.4031],
              [0.7347, 0.0293, 0.7999],
              [0.3971, 0.7544, 0.5695]]],
    <BLANKLINE>
    <BLANKLINE>
            [[[0.4388, 0.6387, 0.5247],
              [0.6826, 0.3051, 0.4635],
              [0.4550, 0.5725, 0.4980]]]]), tensor([[0.0000, 0.0000, 0.1980],
            [1.0000, 1.0000, 0.4162]])]

c                óÆ   <€ V ^8„  d   QhRS[ S[S[P                  S[S[S[3,          3,          ,          RS[RS[RS[RS[ S[S[S[S[	S[
3,          ,          ,          RR/# )é   Ú
lambda_valÚsame_on_batchÚpÚkeepdimÚ	data_keysÚreturnN)r   r   ÚtorchÚTensorr   ÚfloatÚboolr   ÚstrÚintr   )ÚformatÚ__classdict__s   "€Ú]C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\mix\mixup.pyÚ__annotate__ÚRandomMixUpV2.__annotate__m   s�   ø€ ÷ 	Eñ 	Eá™U¡5§<¡<±±u¹e°|Õ1DÐ#DÕEÕFð	Eñ ð	Eñ ð		Eñ
 ð	Eñ ™D¡¡s©C±Ð'8Õ!9Õ:Õ;ð	Eð 
ñ	Eó    c                óf   <€ \         SV `  R W2WER7       \        P                  ! VR R7      V n        R# )ç      ð?)r   Úp_batchr   r   r   )r   N)ÚsuperÚ__init__ÚrgÚMixupGeneratorÚ_param_generator)Úselfr   r   r   r   r   Ú	__class__s   &&&&&&€r    r(   ÚRandomMixUpV2.__init__m   s/   ø€ ô 	‰Ñ˜3¨ÐPWÐÔmÜ "× 1Ò 1°*ÀÔ DˆÖ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   ÚinputÚparamsÚmaybe_flagsr   ©r   r   r   r   r   r   )r   r   s   "€r    r!   r"   x   sU   ø€ ÷ 	7ñ 	7Ù—\‘\ð	7Ù+/±±U·\±\Ð0AÕ+Bð	7ÙQYÑZ^Ñ_bÑdgÐ_gÕZhÕQið	7á	�‰ñ	7r#   c                ó.  € VP                  ^ \        VR,          VP                  4      R7      p\        VR,          P                  R^^^4      VP                  VP                  4      pVP                  V4      pV^V,
          ,          WE,          ,           # )r   Úmixup_pairs©ÚdimÚindexÚmixup_lambdaséÿÿÿÿ)Úindex_selectr   ÚdeviceÚviewÚdtypeÚ	expand_as)r,   r1   r2   r3   Úinput_permuteÚlams   &&&&  r    Úapply_transformÚRandomMixUpV2.apply_transformx   s‡   € ð ×*Ñ*¨qÔ8NÈvÐVcÕOdÐfk×frÑfrÓ8sÐ*Ótˆô % V¨OÕ%<×%AÑ%AÀ"ÀaÈÈAÓ%NÐPU×P\ÑP\Ð^c×^iÑ^iÓjˆØ�m‰m˜EÓ"ˆØ˜˜C�Õ  =Õ#6Õ6Ð6r#   c          	      óª   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[S[3,          ,          RS[ P                  /# r0   r4   )r   r   s   "€r    r!   r"   ƒ   sU   ø€ ÷ 
ñ 
Ù—\‘\ð
Ù+/±±U·\±\Ð0AÕ+Bð
ÙQYÑZ^Ñ_bÑdgÐ_gÕZhÕQið
á	�‰ñ
r#   c           
     óÎ  € \         P                  ! \        VR ,          P                  4       4      4      pV\        P
                  \        P                  39   d   TM\        P
                  p\        P                  ! VP                  VP                  VR7      VP                  VP                  VR7      \        P                  ! \        V4      3VP                  VR7      .R4      # )r?   ©r=   r?   r;   )r   Úto_torchr   Úitemr   Úfloat32Úfloat64ÚstackÚtor=   ÚzerosÚlen)r,   r1   r2   r3   Úimage_dtypeÚ
calc_dtypes   &&&&  r    Úapply_non_transform_classÚ'RandomMixUpV2.apply_non_transform_classƒ   s£   € ô —n’n¤S¨°­×)=Ñ)=Ó)?Ó%@ÓAˆØ$/´E·M±MÄ5Ç=Á=Ð3QÔ$Q‘[ÔW\×WdÑWdˆ
Ü�{Š{à—‘ §¡°J�Ó?Ø—‘ §¡°J�Ó?Ü—’œS ›Z˜M°%·,±,ÀjÔ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                  /# r0   r4   )r   r   s   "€r    r!   r"   ‘   sU   ø€ ÷ 
ñ 
Ù—\‘\ð
Ù+/±±U·\±\Ð0AÕ+Bð
ÙQYÑZ^Ñ_bÑdgÐ_gÕZhÕQið
á	�‰ñ
r#   c           	     ó  € VP                  ^ \        VR,          VP                  4      R7      p\        P                  ! \        VR,          P                  4       4      4      pV\        P                  \        P                  39   d   TM\        P                  p\        P                  ! VP                  VP                  VR7      VP                  VP                  VR7      \        VR,          VP                  V4      .R4      # )r   r6   r7   r?   rG   r:   r;   )r<   r   r=   r   rH   r   rI   r   rJ   rK   rL   rM   )r,   r1   r2   r3   Úlabels_permuterP   rQ   s   &&&&   r    Úapply_transform_classÚ#RandomMixUpV2.apply_transform_class‘   sÌ   € ð ×+Ñ+°Ô9OÐPVÐWdÕPeÐgl×gsÑgsÓ9tÐ+Óuˆä—n’n¤S¨°­×)=Ñ)=Ó)?Ó%@ÓAˆØ$/´E·M±MÄ5Ç=Á=Ð3QÔ$Q‘[ÔW\×WdÑWdˆ
Ü�{Š{à—‘ §¡°J�Ó?Ø×!Ñ!¨¯©¸ZÐ!ÓHÜ& v¨oÕ'>ÀÇÁÈjÓYðð
 ó
ð 	
r#   )r+   )NFr%   FN)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r(   rC   rR   rW   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r-   r   s   @@r    r   r      s;   ù‡ € ñN÷`	Eõ 	E÷	7ò 	7÷
ò 
÷
÷ 
ò 
r#   r   )Útypingr   r   r   r   r   r   r   Úkornia.augmentationr	   r)   Ú kornia.augmentation._2d.mix.baser
   Úkornia.constantsr   r   Úkornia.core.utilsr   r   © r#   r    Ú<module>rg      s+   ð÷$ ;× :ã å 6Ý Bß +Ý 4ôC
Ð)ö C
r#   