
    x h                         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y)    )Sequence)AnyCallableOptional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     /home/developers/rajanand/mypropertyqr-fmb-refixing-v2/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.forward1   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_repr8   =     	-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   r8   )r   r	   r8   r   s      r   r   zRandomApply.__init__U   sc    *x&?@hii$qC_``  _``r   c                 4    | j                   | j                  dS )Nr	   r8   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randr8   r	   r   s        r   r#   zRandomApply.forwardc   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_reprn   r.   r   )g      ?)r/   r0   r1   r2   _transformsr7   _v1_transform_clsr   r   r   r   r:   floatr   dictr3   r   r=   r#   r-   r4   r5   s   @r   r7   r7   ?   sx    & $//	5();R]])J#K 	PU 	`d 	<$sCx. <	s 	s 	(C (r   r7   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	   r8   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	   sumr8   )r   r	   r8   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   )intr?   multinomialtensorr8   r	   )r   r   idxr!   s       r   r#   zRandomChoice.forward   s?    %##ELL$8!<=OOC(	&!!r   )N)r/   r0   r1   r2   r   r   r   listrD   r   r   r#   r4   r5   s   @r   rG   rG   u   sO    	 $(.X&. DK . 
	.&"s "s "r   rG   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   r?   randpermr	   )r   r   r    rP   r!   r"   s         r   r#   zRandomOrder.forward   s\    f+/>>#doo"67 	@C,I(G /WgZF	@ r   )
r/   r0   r1   r2   r   r   r   r   r#   r4   r5   s   @r   rS   rS      s3    %8H#5 %$ %s s r   rS   )collections.abcr   typingr   r   r   r   r?   r   torchvisionr	   rB   torchvision.transforms.v2r
   r   r7   rG   rS    r   r   <module>r\      sM    $ 1 1   1 /1(i 1(h3() 3(l""9 ""J) r   