a
    d
                     @  s   d dl mZ d dl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mZmZ ddd	d
dZddd	ddZddd	ddZddddddZddddddZddddddZdS )    )annotations)AnyCallableListTupleTypeUnionN)
datapoints)sequence_to_str)get_dimensionsget_spatial_sizeis_simple_tensorz	List[Any]zdatapoints.BoundingBox)flat_inputsreturnc                 C  s8   dd | D }|st dnt|dkr0td| S )Nc                 S  s   g | ]}t |tjr|qS  )
isinstancer	   BoundingBox.0inptr   r   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchvision/transforms/v2/utils.py
<listcomp>       z&query_bounding_box.<locals>.<listcomp>z'No bounding box was found in the sample   z+Found multiple bounding boxes in the sample)	TypeErrorlen
ValueErrorpop)r   Zbounding_boxesr   r   r   query_bounding_box   s    
r   zTuple[int, int, int]c                 C  sV   dd | D }|st dn"t|dkr>tdtt| | \}}}|||fS )Nc                 S  s8   h | ]0}t |tjtjjtjfs(t|rtt|qS r   )r   r	   ImagePILVideor   tupler   r   r   r   r   	<setcomp>   s    zquery_chw.<locals>.<setcomp>z)No image or video was found in the sampler   z/Found multiple CxHxW dimensions in the sample: r   r   r   r
   sortedr   )r   Zchwschwr   r   r   	query_chw   s    
r)   zTuple[int, int]c                 C  sR   dd | D }|st dn"t|dkr>tdtt| | \}}||fS )Nc              	   S  s@   h | ]8}t |tjtjjtjtjtjfs0t|rtt	|qS r   )
r   r	   r   r    r!   ZMaskr   r   r"   r   r   r   r   r   r#   $   s   z%query_spatial_size.<locals>.<setcomp>z=No image, video, mask or bounding box was found in the sampler   z-Found multiple HxW dimensions in the sample: r$   )r   sizesr'   r(   r   r   r   query_spatial_size#   s    
r+   r   z.Tuple[Union[Type, Callable[[Any], bool]], ...]bool)objtypes_or_checksr   c                 C  s2   |D ](}t |trt | |rn|| r dS qdS NTFr   type)r-   r.   type_or_checkr   r   r   
check_type4   s    r3   z"Union[Type, Callable[[Any], bool]])r   r.   r   c                 G  s   | D ]}t ||r dS qdS r/   )r3   )r   r.   r   r   r   r   has_any;   s    
r4   c                 G  s@   |D ]6}| D ]&}t |tr&t ||rn||r qq dS qdS )NFTr0   )r   r.   r2   r   r   r   r   has_allB   s    r5   )
__future__r   typingr   r   r   r   r   r   Z	PIL.Imager    Ztorchvisionr	   Ztorchvision._utilsr
   Z$torchvision.transforms.v2.functionalr   r   r   r   r)   r+   r3   r4   r5   r   r   r   r   <module>   s    	