a
    d                     @   s   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZ ddgZG d	d deZG d
d dejZdS )    )OrderedDict)AnyIteratorList
NamedTupleOptionalTupleUnionN)MixAugmentationBase)MixAugmentationBaseV2)_AugmentationBaseSequentialBase	ParamItemc                   @   s*   e Zd ZU eed< eeeef  ed< dS )r   namedataN)	__name__
__module____qualname__str__annotations__r   r	   dictlist r   r   k/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/augmentation/container/base.pyr      s   
c                       s  e Zd ZdZddddejee ee ee dd fddZd1ee ee ee dddd	Z	e
ejd
ddZeee dddZejee ddddZeee dddZejee ddddZeee dddZejee ddddZddddZeddddZejee dd d!Zejeee
ejf  d"d#d$Zee eee
ejf  d%d&d'Zeee
ejf  ee d(d)d*Zeed%d+d,Zd2ejee e f eejejf d.d/d0Z!  Z"S )3r   a  SequentialBase for creating kornia modulized processing pipeline.

    Args:
        *args : a list of kornia augmentation and image operation modules.
        same_on_batch: apply the same transformation across the batch.
            If None, it will not overwrite the function-wise settings.
        return_transform: if ``True`` return the matrix describing the transformation
            applied to each. If None, it will not overwrite the function-wise settings.
        keepdim: whether to keep the output shape the same as input (True) or broadcast it
            to the batch form (False). If None, it will not overwrite the function-wise settings.
    N)same_on_batchreturn_transformkeepdim)argsr   r   r   returnc                   s   t  }t|D ]@\}}t|tjs2td| d||jj d| |i qt	 
| || _|| _|| _d | _| ||| d S )Nz1Only nn.Module are supported at this moment. Got ._)r   	enumerate
isinstancennModuleNotImplementedErrorupdate	__class__r   super__init___same_on_batch_return_transform_keepdim_paramsupdate_attribute)selfr   r   r   r   _argsidxmodr'   r   r   r)       s    zSequentialBase.__init__)r   r   r   r   c                 C   sn   |   D ]`}t|tttfr8|d ur*||_|d ur8||_t|trP|d urP||_t|tr|	||| qd S N)
childrenr"   r   r
   r   r   r   r   r   r.   )r/   r   r   r   r2   r   r   r   r.   4   s    

zSequentialBase.update_attribute)targetr   c                 C   sr   |dkr| S | d}| }|D ]N}t||sDt| d | d t||}t|tjjstd| d q|S )a  Get submodule.

        This code is taken from torch 1.9.0 since it is not introduced
        back to torch 1.7.1. We included this for maintaining more
        backward torch versions.

        Args:
            target: The fully-qualified string name of the submodule
                to look for. (See above example for how to specify a
                fully-qualified string.)

        Returns:
            torch.nn.Module: The submodule referenced by ``target``

        Raises:
            AttributeError: If the target string references an invalid
                path or resolves to something that is not an
                ``nn.Module``
         r   z has no attribute ``z` is not an nn.Module)	splithasattrAttributeErrorZ	_get_namegetattrr"   torchr#   r$   )r/   r6   Zatomsr2   itemr   r   r   get_submoduleG   s    


zSequentialBase.get_submodule)r   c                 C   s   | j S r4   )r*   r/   r   r   r   r   m   s    zSequentialBase.same_on_batch)r   r   c                 C   s   || _ | j|d d S )N)r   )r*   r.   )r/   r   r   r   r   r   q   s    c                 C   s   | j S r4   )r+   r@   r   r   r   r   v   s    zSequentialBase.return_transform)r   r   c                 C   s   || _ | j|d d S )N)r   )r+   r.   )r/   r   r   r   r   r   z   s    c                 C   s   | j S r4   )r,   r@   r   r   r   r      s    zSequentialBase.keepdim)r   r   c                 C   s   || _ | j|d d S )N)r   )r,   r.   )r/   r   r   r   r   r      s    c                 C   s
   d| _ dS )z!Reset self._params state to None.N)r-   r@   r   r   r   clear_state   s    zSequentialBase.clear_state)paramr   c                 C   s$   | j du r|g| _ n| j | dS )zUpdate self._params state.N)r-   append)r/   rB   r   r   r   update_params   s    

zSequentialBase.update_params)batch_shaper   c                 C   s   t d S r4   r%   )r/   rE   r   r   r   forward_parameters   s    z!SequentialBase.forward_parameters)indicesr   c                 c   s$   t |  }|D ]}|| V  qd S r4   )r   named_children)r/   rH   modulesr1   r   r   r   get_children_by_indices   s    z&SequentialBase.get_children_by_indices)paramsr   c                 c   s<   t |  }|D ]&}|t t|   |j V  qd S r4   )r   rI   r   keysindexr   )r/   rL   rJ   rB   r   r   r   get_children_by_params   s    z%SequentialBase.get_children_by_params)named_modulesr   c                 c   s   |D ]\}}t |d V  qd S r4   )r   )r/   rP   r   r    r   r   r   get_params_by_module   s    z#SequentialBase.get_params_by_modulec                 C   s   t d S r4   rF   )r/   rL   r   r   r   contains_label_operations   s    z(SequentialBase.contains_label_operations      )input	dim_ranger   c                 C   sb   |j }t||d k s&t||d kr<td| d| dt|j |d k rX|d }q<||j fS )zFill tensor dim to the upper bound of dim_range.

        If input tensor dim is smaller than the lower bound of dim_range, an error will be thrown out.
        r      zinput shape expected to be in z while got r   N)shapelenRuntimeError)r/   rV   rW   Z	ori_shaper   r   r   autofill_dim   s     
zSequentialBase.autofill_dim)NNN)rS   )#r   r   r   __doc__r#   r$   r   boolr)   r.   r   r?   propertyr   setterr   r   rA   r   rD   r=   Sizer   r   rG   ZTensorr   r   rK   rO   rQ   rR   intr\   __classcell__r   r   r3   r   r      sR      & "")collectionsr   typingr   r   r   r   r   r   r	   r=   Ztorch.nnr#   Zkornia.augmentationr
   Z kornia.augmentation._2d.mix.baser   Zkornia.augmentation.baser   __all__r   Z
Sequentialr   r   r   r   r   <module>   s   $