
    %`i                         d dl mZ d dl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  G d de          Z G d	 d
e          Z G d de          Z G d de          ZdS )    )Sequence)AnyCallableOptionalUnionN)nn)
transforms)	Transformc                   T     e Zd ZdZdee         ddf fdZdedefdZde	fdZ
 xZS )	Composea  Composes several transforms together.

    This transform does not support torchscript.
    Please, see the note below.

    Args:
        transforms (list of ``Transform`` objects): list of transforms to compose.

    Example:
        >>> transforms.Compose([
        >>>     transforms.CenterCrop(10),
        >>>     transforms.PILToTensor(),
        >>>     transforms.ConvertImageDtype(torch.float),
        >>> ])

    .. note::
        In order to script the transformations, please use ``torch.nn.Sequential`` as below.

        >>> transforms = torch.nn.Sequential(
        >>>     transforms.CenterCrop(10),
        >>>     transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
        >>> )
        >>> scripted_transforms = torch.jit.script(transforms)

        Make sure to use only scriptable transformations, i.e. that work with ``torch.Tensor``, does not require
        `lambda` functions or ``PIL.Image``.

    r	   returnNc                     t                                                       t          |t                    st	          d          |st          d          || _        d S N5Argument transforms should be a sequence of callablesPass at least one transform)super__init__
isinstancer   	TypeError
ValueErrorr	   selfr	   	__class__s     x/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchvision/transforms/v2/_container.pyr   zCompose.__init__)   s\    *h// 	<STTT 	<:;;;$    inputsc                 X    t          |          dk    }| j        D ]} || }|r|n|f}|S N   )lenr	   r   r   needs_unpacking	transformoutputss        r   forwardzCompose.forward1   sG    f++/ 	@ 	@Ii(G /?WWgZFFr   c                 t    g }| j         D ]}|                    d|            d                    |          S Nz    
r	   appendjoinr   format_stringts      r   
extra_reprzCompose.extra_repr8   G     	- 	-A  ,,,,yy'''r   )__name__
__module____qualname____doc__r   r   r   r   r%   strr/   __classcell__r   s   @r   r   r      s         :%8H#5 %$ % % % % % %s s    (C ( ( ( ( ( ( ( (r   r   c                        e Zd ZdZej        Zddeee	         e
j        f         deddf fdZdeeef         fdZd	edefd
ZdefdZ xZS )RandomApplya  Apply randomly a list of transformations with a given probability.

    .. note::
        In order to script the transformation, please use ``torch.nn.ModuleList`` as input instead of list/tuple of
        transforms as shown below:

        >>> transforms = transforms.RandomApply(torch.nn.ModuleList([
        >>>     transforms.ColorJitter(),
        >>> ]), p=0.3)
        >>> scripted_transforms = torch.jit.script(transforms)

        Make sure to use only scriptable transformations, i.e. that work with ``torch.Tensor``, does not require
        `lambda` functions or ``PIL.Image``.

    Args:
        transforms (sequence or torch.nn.Module): list of transformations
        p (float): probability of applying the list of transforms
          ?r	   pr   Nc                 "   t                                                       t          |t          t          j        f          st          d          |st          d          || _        d|cxk    rdk    sn t          d          || _	        d S )NzJArgument transforms should be a sequence of callables or a `nn.ModuleList`r   g        g      ?z@`p` should be a floating point value in the interval [0.0, 1.0].)
r   r   r   r   r   
ModuleListr   r   r	   r;   )r   r	   r;   r   s      r   r   zRandomApply.__init__U   s    *x&?@@ 	<hiii 	<:;;;$qC_```r   c                      | j         | j        dS )Nr	   r;   r?   )r   s    r    _extract_params_for_v1_transformz,RandomApply._extract_params_for_v1_transformb   s    "oDF;;;r   r   c                     t          |          dk    }t          j        d          | j        k    r|r|n|d         S | j        D ]} || }|r|n|f}|S )Nr   r   )r    torchrandr;   r	   r!   s        r   r%   zRandomApply.forwarde   so    f++/:a==DF"",;66&); 	@ 	@Ii(G /?WWgZFFr   c                 t    g }| j         D ]}|                    d|            d                    |          S r'   r)   r,   s      r   r/   zRandomApply.extra_reprp   r0   r   )r:   )r1   r2   r3   r4   _transformsr9   _v1_transform_clsr   r   r   r   r=   floatr   dictr5   r   r@   r%   r/   r6   r7   s   @r   r9   r9   ?   s         & $/ 5();R])J#K PU `d      <$sCx. < < < <	s 	s 	 	 	 	(C ( ( ( ( ( ( ( (r   r9   c                   h     e Zd ZdZ	 d	dee         deee                  ddf fdZ	de
de
fdZ xZS )
RandomChoicea  Apply single transformation randomly picked from a list.

    This transform does not support torchscript.

    Args:
        transforms (sequence or torch.nn.Module): list of transformations
        p (list of floats or None, optional): probability of each transform being picked.
            If ``p`` doesn't sum to 1, it is automatically normalized. If ``None``
            (default), all transforms have the same probability.
    Nr	   r;   r   c                    t          |t                    st          d          |st          d          |dgt	          |          z  }nOt	          |          t	          |          k    r/t          dt	          |           dt	          |                     t                                                       || _        t          |          fd|D             | _	        d S )Nr   r   r   z4Length of p doesn't match the number of transforms: z != c                     g | ]}|z  S  rM   ).0probtotals     r   
<listcomp>z)RandomChoice.__init__.<locals>.<listcomp>   s    ---4$,---r   )
r   r   r   r   r    r   r   r	   sumr;   )r   r	   r;   rP   r   s      @r   r   zRandomChoice.__init__   s    
 *h// 	<STTT 	<:;;;9c*oo%AAVVs:&&qTWXYTZTZqq`cdn`o`oqqrrr$A----1---r   r   c                     t          t          j        t          j        | j                  d                    }| j        |         } || S r   )intrB   multinomialtensorr;   r	   )r   r   idxr#   s       r   r%   zRandomChoice.forward   sA    %#EL$8$8!<<==OC(	y&!!r   )N)r1   r2   r3   r4   r   r   r   listrG   r   r   r%   r6   r7   s   @r   rJ   rJ   w   s        	 	 $(. .X&. DK . 
	. . . . . .("s "s " " " " " " " "r   rJ   c                   H     e Zd ZdZdee         ddf fdZdedefdZ xZ	S )RandomOrderzApply a list of transformations in a random order.

    This transform does not support torchscript.

    Args:
        transforms (sequence or torch.nn.Module): list of transformations
    r	   r   Nc                     t          |t                    st          d          |st          d          t	                                                       || _        d S r   )r   r   r   r   r   r   r	   r   s     r   r   zRandomOrder.__init__   s\    *h// 	<STTT 	<:;;;$r   r   c                     t          |          dk    }t          j        t          | j                            D ]}| j        |         } || }|r|n|f}|S r   )r    rB   randpermr	   )r   r   r"   rW   r#   r$   s         r   r%   zRandomOrder.forward   se    f++/>#do"6"677 	@ 	@C,Ii(G /?WWgZFFr   )
r1   r2   r3   r4   r   r   r   r   r%   r6   r7   s   @r   rZ   rZ      s|         %8H#5 %$ % % % % % %s s        r   rZ   )collections.abcr   typingr   r   r   r   rB   r   torchvisionr	   rE   torchvision.transforms.v2r
   r   r9   rJ   rZ   rM   r   r   <module>rb      s/   $ $ $ $ $ $ 1 1 1 1 1 1 1 1 1 1 1 1        1 1 1 1 1 1 / / / / / /1( 1( 1( 1( 1(i 1( 1( 1(h5( 5( 5( 5( 5() 5( 5( 5(p#" #" #" #" #"9 #" #" #"L    )     r   