o
    oi                     @   st  U d dl mZmZmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ ddlmZ d	d
gddgddgddgddgddgddgddgddgddgddgddgddgddgddgdd gd!d"gd#dgd$dgddgddgddgddgddgddggZee	 ed%< d&d'gd(d)gd*d+gd,d-gd.d/gd0d1gd2d3gd4d5gdd6gd7d8gd9d:gd;d<gd=d>gd?d@gdAdBgdCdgdCdgdDdgdEdFgdGdHgdIdJgdKd-gdJdLgdd&gd-dJggZee	 edM< dNdOgdPdQgddRgdSdgddTgdNdEgdPdUgdVdWgdSdEgddTgdNdXgdYdQgd/dZgdSdgd[d\gd]d^gd_d`gdd\gdadbgdcdgdddegdfd]gdgdhgdidjgdkd&ggZee	 edl< G dmdn dne
ZdoS )p    )IteratorListOptionalTupleUnion)Categorical)SUBPOLICY_CONFIGPolicyAugmentBasePolicySequential)	ParamItem)Moduletensor   )ops)	posterize皙?   )rotate333333?	   )solarizer      )auto_contrastr   N)equalize皙?N)r   r   N)r   r      )r   r      )r   r   N)r   皙?   )r   r   r   )r   r      )r   r   r   )r         ?N)r   r   r    )r   r   r   )r   r   r   )colorr   r   )r   r   r   )r           N)invertr   N)r"   r   r   )contrastr!   r   )r"   r!      )r"   r   r   )r   r   r   )	sharpnessr   r   )shear_xr   r   imagenet_policy)r$   皙?N)r%   r   r   )r   ffffff?r&   )translate_x333333?r   )r'   r   r   )r'   ?r    )shear_y      ?r   )translate_yr+   r   )r   r0   N)r   r.   N)r/   r   r   )r   r-   r   )r"   r   r    )
brightnessr   r   )r'   r-   r   )r2   r+   r   )r   r0   N)r%   r   r   )r'   r   r   )r"   r+   r   )r,   r0   r   )r   r-   N)r   r   N)r1   r   r    )r'   r   r   )r2   r.   r   )r"   r   r   )r   r0   r&   )r$   r#   N)r   r   N)r"   r.   r   )r   r   N)r   r   r   )r2   r*   r    )r"   r+   r   )r   r   r   )r   r.   N)r1   r.   r   )r   r   r    cifar10_policy)r(   r.   r   )r$   r   N)r/   r.   r   )r$   r+   N)r   r   r   )r$   r.   N)r   r.   r    )r$   r   N)r/   r.   r   )r   r   r   )r   r-   r    )r/   r   r   )r1   r   r   )r%   r-   r    )r   r   r   )r$   r   N)r1   r#   r&   )r/   r+   r   )r   r   r   )r/   r-   r   )r,   r.   r    )r(   r*   r   )r   r+   r&   )r1   r   r   )r/   r   r   )r(   r+   r   )r1   r   r    )r/   r   r   )r   r+   N)r(   r+   r&   svhn_policyc                       sx   e Zd ZdZ	ddeeee f deddf fdd	Zd
ede	fddZ
ddeee  deeeef  fddZ  ZS )AutoAugmenta3  Apply AutoAugment :cite:`cubuk2018autoaugment` searched strategies.

    Args:
        policy: a customized policy config or presets of "imagenet", "cifar10", and "svhn".
        transformation_matrix_mode: computation mode for the chained transformation matrix, via `.transform_matrix`
                                    attribute.
                                    If `silent`, transformation matrix will be computed silently and the non-rigid
                                    modules will be ignored as identity transformations.
                                    If `rigid`, transformation matrix will be computed silently and the non-rigid
                                    modules will trigger errors.
                                    If `skip`, transformation matrix will be totally ignored.

    Examples:
        >>> import torch
        >>> import kornia.augmentation as K
        >>> in_tensor = torch.rand(5, 3, 30, 30)
        >>> aug = K.AugmentationSequential(AutoAugment())
        >>> aug(in_tensor).shape
        torch.Size([5, 3, 30, 30])

    imagenetsilentpolicytransformation_matrix_modereturnNc                    s   |dkrt }n |dkrt}n|dkrt}nt|ttfr|}ntd| dt j||d t	dt
|  gt
|  }t|| _d S )Nr6   cifar10svhnzInvalid policy `z`.)r9   r!   )r)   r3   r4   
isinstancelisttupleNotImplementedErrorsuper__init__r   lenr   rand_selector)selfr8   r9   _policyselection_weights	__class__ d/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/auto/autoaugment/autoaugment.pyrB      s   zAutoAugment.__init__	subpolicyc                 C   s   t dd |D  S )Nc                 S   s"   g | ]\}}}t t|||qS rJ   )getattrr   ).0nameprobmagrJ   rJ   rK   
<listcomp>   s   " z<AutoAugment.compose_subpolicy_sequential.<locals>.<listcomp>r
   )rE   rL   rJ   rJ   rK   compose_subpolicy_sequential   s   z(AutoAugment.compose_subpolicy_sequentialparamsc                 C   s(   |d u r| j d}| |S | |S )N)r   )rD   sampleget_children_by_indicesget_children_by_params)rE   rT   idxrJ   rJ   rK   get_forward_sequence   s   

z AutoAugment.get_forward_sequence)r6   r7   )N)__name__
__module____qualname____doc__r   strr   r   rB   r   rS   r   r   r   r   r   rY   __classcell__rJ   rJ   rH   rK   r5   t   s    0r5   N)typingr   r   r   r   r   torch.distributionsr   kornia.augmentation.auto.baser   r	   *kornia.augmentation.auto.operations.policyr   $kornia.augmentation.container.paramsr   kornia.corer   r    r   r)   __annotations__r3   r4   r5   rJ   rJ   rJ   rK   <module>   s   