
    kh                         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  G d de      Z G d d	e      Z G d
 de      Z G d de      Zy)    )AnyCallableDictListOptionalSequenceUnionN)nn)
transforms)	Transformc                   N     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      || _        y )N5Argument transforms should be a sequence of callableszPass at least one transform)super__init__
isinstancer   	TypeError
ValueErrorr   selfr   	__class__s     `/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/transforms/v2/_container.pyr   zCompose.__init__(   s:    *h/STT:;;$    inputsc                 \    t        |      dkD  }| j                  D ]  } || }|r|n|f} S N   )lenr   r   r   needs_unpacking	transformoutputss        r   forwardzCompose.forward0   s@    f+/ 	@I(G /WgZF	@ r   c                 r    g }| j                   D ]  }|j                  d|         dj                  |      S Nz    
r   appendjoinr   format_stringts      r   
extra_reprzCompose.extra_repr7   =     	-A  4s,	-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      || _        d|cxk  rdk  st        d       t        d      || _	        y )NzJArgument transforms should be a sequence of callables or a `nn.ModuleList`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__T   sc    *x&?@hii$qC_``  _``r   c                 4    | j                   | j                  dS )Nr   r:   r>   )r   s    r    _extract_params_for_v1_transformz,RandomApply._extract_params_for_v1_transform_   s    "ooDFF;;r   r   c                     t        |      dkD  }t        j                  d      | j                  k\  r	|r|S |d   S | j                  D ]  } || }|r|n|f} S )Nr   r   )r    torchrandr:   r   r!   s        r   r%   zRandomApply.forwardb   se    f+/::a=DFF",6;&); 	@I(G /WgZF	@ r   c                 r    g }| j                   D ]  }|j                  d|         dj                  |      S r'   r)   r,   s      r   r/   zRandomApply.extra_reprm   r0   r   )g      ?)r1   r2   r3   r4   _transformsr9   _v1_transform_clsr	   r   r   r
   r<   floatr   r   r5   r   r?   r%   r/   r6   r7   s   @r   r9   r9   >   sx    & $//	5();R]])J#K 	PU 	`d 	<$sCx. <	s 	s 	(C (r   r9   c                   V     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                 N   t        |t              st        d      |dgt        |      z  }n:t        |      t        |      k7  r#t	        dt        |       dt        |             t
        |           || _        t        |      }|D cg c]  }||z  	 c}| _	        y c c}w )Nr   r   z4Length of p doesn't match the number of transforms: z != )
r   r   r   r    r   r   r   r   sumr:   )r   r   r:   totalprobr   s        r   r   zRandomChoice.__init__   s    
 *h/STT9c*o%AVs:&STWXYTZS[[_`cdn`o_pqrr$A+,-4$,--s   B"r   c                     t        t        j                  t        j                  | j                        d            }| j
                  |   } || S r   )intrA   multinomialtensorr:   r   )r   r   idxr#   s       r   r%   zRandomChoice.forward   s?    %##ELL$8!<=OOC(	&!!r   )N)r1   r2   r3   r4   r   r   r   r   rF   r   r   r%   r6   r7   s   @r   rH   rH   t   sO    	 $(.X&. DK . 
	.&"s "s "r   rH   c                   B     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                 f    t        |t              st        d      t        |           || _        y )Nr   )r   r   r   r   r   r   r   s     r   r   zRandomOrder.__init__   s+    *h/STT$r   r   c                     t        |      dkD  }t        j                  t        | j                              D ]  }| j                  |   } || }|r|n|f} S r   )r    rA   randpermr   )r   r   r"   rQ   r#   r$   s         r   r%   zRandomOrder.forward   s\    f+/>>#doo"67 	@C,I(G /WgZF	@ r   )
r1   r2   r3   r4   r   r   r   r   r%   r6   r7   s   @r   rS   rS      s3    %8H#5 %$ %s s r   rS   )typingr   r   r   r   r   r   r	   rA   r
   torchvisionr   rD   torchvision.transforms.v2r   r   r9   rH   rS    r   r   <module>r[      sM    G G G   1 /1(i 1(h3() 3(l""9 ""J) r   