
    \h                         S SK Jr  S SKJrJrJrJr  S SKrS SKJr  S SK	J
r  S SKJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      rg)    )Sequence)AnyCallableOptionalUnionN)nn
transforms)	Transformc                   ^   ^  \ rS rSrSrS\\   SS4U 4S jjrS\S\4S jr	S\
4S	 jrS
rU =r$ )Compose   a_  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U ]  5         [        U[        5      (       d  [	        S5      eU(       d  [        S5      eXl        g )N5Argument transforms should be a sequence of callableszPass at least one transform)super__init__
isinstancer   	TypeError
ValueErrorr
   selfr
   	__class__s     ^/var/www/fran/franai/venv/lib/python3.13/site-packages/torchvision/transforms/v2/_container.pyr   Compose.__init__)   s;    *h//STT:;;$    inputsc                 j    [        U5      S:  nU R                   H  nU" U6 nU(       a  UOU4nM     W$ N   )lenr
   r   r   needs_unpacking	transformoutputss        r   forwardCompose.forward1   s9    f+/I(G /WgZF ) r   c                 v    / nU R                    H  nUR                  SU 35        M     SR                  U5      $ Nz    
r
   appendjoinr   format_stringts      r   
extra_reprCompose.extra_repr8   8    A  4s, !yy''r   r	   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r&   strr1   __static_attributes____classcell__r   s   @r   r   r      sD    :%8H#5 %$ %s s (C ( (r   r   c                      ^  \ rS rSrSr\R                  rSS\\	\
   \R                  4   S\SS4U 4S jjjrS\\\4   4S jrS	\S\4S
 jrS\4S jrSrU =r$ )RandomApply?   a  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U ]  5         [        U[        [        R
                  45      (       d  [        S5      eXl        SUs=::  a  S::  d  O  [        S5      eX l	        g )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   RandomApply.__init__U   sQ    *x&?@@hii$qC_``r   c                 4    U R                   U R                  S.$ )Nr
   r@   rE   )r   s    r    _extract_params_for_v1_transform,RandomApply._extract_params_for_v1_transform`   s    "ooDFF;;r   r   c                     [        U5      S:  n[        R                  " S5      U R                  :  a  U(       a  U$ US   $ U R                   H  nU" U6 nU(       a  UOU4nM     W$ )Nr    r   )r!   torchrandr@   r
   r"   s        r   r&   RandomApply.forwardc   s^    f+/::a=DFF",6;&);I(G /WgZF ) r   c                 v    / nU R                    H  nUR                  SU 35        M     SR                  U5      $ r)   r+   r.   s      r   r1   RandomApply.extra_reprn   r3   r   r@   r
   )g      ?)r4   r5   r6   r7   r8   _transformsr>   _v1_transform_clsr   r   r   r   rB   floatr   dictr9   r   rF   r&   r1   r:   r;   r<   s   @r   r>   r>   ?   s    & $//	5();R]])J#K 	PU 	`d 	 	<$sCx. <	s 	s 	(C ( (r   r>   c                   f   ^  \ rS rSrSr SS\\   S\\\	      SS4U 4S jjjr
S\S\4S	 jrS
rU =r$ )RandomChoiceu   a  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                 ^  > [        U[        5      (       d  [        S5      eUc  S/[        U5      -  nO;[        U5      [        U5      :w  a#  [	        S[        U5       S[        U5       35      e[
        TU ]  5         Xl        [        U5      nU Vs/ s H  oDU-  PM	     snU l	        g s  snf )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   RandomChoice.__init__   s    
 *h//STT9c*o%AVs:&STWXYTZS[[_`cdn`o_pqrr$A+,-14,1--s   B*r   c                     [        [        R                  " [        R                  " U R                  5      S5      5      nU R
                  U   nU" U6 $ r   )intrI   multinomialtensorr@   r
   )r   r   idxr$   s       r   r&   RandomChoice.forward   s?    %##ELL$8!<=OOC(	&!!r   rN   )N)r4   r5   r6   r7   r8   r   r   r   listrQ   r   r   r&   r:   r;   r<   s   @r   rT   rT   u   sY    	 $(.X&. DK . 
	. .&"s "s " "r   rT   c                   P   ^  \ rS rSrSrS\\   SS4U 4S jjrS\S\4S jr	S	r
U =r$ )
RandomOrder   zApply 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                 n   > [        U[        5      (       d  [        S5      e[        TU ]  5         Xl        g )Nr   )r   r   r   r   r   r
   r   s     r   r   RandomOrder.__init__   s,    *h//STT$r   r   c                     [        U5      S:  n[        R                  " [        U R                  5      5       H#  nU R                  U   nU" U6 nU(       a  UOU4nM%     W$ r   )r!   rI   randpermr
   )r   r   r#   r_   r$   r%   s         r   r&   RandomOrder.forward   sU    f+/>>#doo"67C,I(G /WgZF 8 r   r	   )r4   r5   r6   r7   r8   r   r   r   r   r&   r:   r;   r<   s   @r   rc   rc      s8    %8H#5 %$ %s s  r   rc   )collections.abcr   typingr   r   r   r   rI   r   torchvisionr
   rO   torchvision.transforms.v2r   r   r>   rT   rc    r   r   <module>ro      sM    $ 1 1   1 /1(i 1(h3() 3(l""9 ""J) r   