§
    ‚ŠtjH,  ã            
       ó6  — d dl Z d dlmZ d dlmZ d dlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZmZ ddlmZ erddlmZ d dlmZ dddeee         z  de dedef
d„Z! G d„ ded¬¦  «        Z"e G d„ de¦  «        ¦   «         Z#dgZ$dS )é    N)ÚIterable)ÚTYPE_CHECKINGé   )ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)ÚIMAGENET_STANDARD_MEANÚIMAGENET_STANDARD_STDÚPILImageResamplingÚSizeDict)ÚImagesKwargs)Ú
TensorTypeÚauto_docstringÚrequires_backendsé   )ÚBeitImageProcessor)ÚDepthEstimatorOutput)Ú
functionalÚinput_imageútorch.TensorÚoutput_sizeÚkeep_aspect_ratioÚmultipleÚreturnc                 ó  — dd„}| j         dd …         \  }}|\  }}||z  }	||z  }
|r+t          d|
z
  ¦  «        t          d|	z
  ¦  «        k     r|
}	n|	}
 ||	|z  |¬¦  «        } ||
|z  |¬¦  «        }t          ||¬¦  «        S )Nr   c                 ó´   — t          | |z  ¦  «        |z  }|� ||k    rt          j        | |z  ¦  «        |z  }||k     rt          j        | |z  ¦  «        |z  }|S ©N)ÚroundÚmathÚfloorÚceil)Úvalr   Úmin_valÚmax_valÚxs        úa/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/dpt/modular_dpt.pyÚconstrain_to_multiple_ofz>get_resize_output_image_size.<locals>.constrain_to_multiple_of0   sd   € Ý�#˜‘.Ñ!Ô! HÑ,ˆàÐ 1 w¢; ;Ý”
˜3 ™>Ñ*Ô*¨XÑ5ˆAàˆwŠ;ˆ;Ý”	˜# ™.Ñ)Ô)¨HÑ4ˆAàˆó    éþÿÿÿé   )r   ©ÚheightÚwidth)r   N)ÚshapeÚabsr   )r   r   r   r   r(   Úinput_heightÚinput_widthÚoutput_heightÚoutput_widthÚscale_heightÚscale_widthÚ
new_heightÚ	new_widths                r'   Úget_resize_output_image_sizer9   *   sÐ   € ð	ð 	ð 	ð 	ð !,Ô 1°"°#°#Ô 6Ñ€L�+Ø"-Ñ€M�<ð ! <Ñ/€LØ Ñ,€Kàð 'åˆq�;‰ÑÔ¥# a¨,Ñ&6Ñ"7Ô"7Ò7Ð7à&ˆLˆLð 'ˆKà)Ð)¨,¸Ñ*EÐPXÐYÑYÔY€JØ(Ð(¨°{Ñ)BÈXÐVÑVÔV€Iå˜:¨YÐ7Ñ7Ô7Ð7r)   c                   ó<   — e Zd ZU dZeed<   eed<   eed<   eed<   dS )ÚDPTImageProcessorKwargsa=  
    ensure_multiple_of (`int`, *optional*, defaults to 1):
        If `do_resize` is `True`, the image is resized to a size that is a multiple of this value. Can be overridden
        by `ensure_multiple_of` in `preprocess`.
    keep_aspect_ratio (`bool`, *optional*, defaults to `False`):
        If `True`, the image is resized to the largest possible size such that the aspect ratio is preserved. Can
        be overridden by `keep_aspect_ratio` in `preprocess`.
    do_reduce_labels (`bool`, *optional*, defaults to `self.do_reduce_labels`):
        Whether or not to reduce all label values of segmentation maps by 1. Usually used for datasets where 0
        is used for background, and background itself is not included in all classes of a dataset (e.g.
        ADE20k). The background label will be replaced by 255.
    Úensure_multiple_ofÚsize_divisorr   Údo_reduce_labelsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚ__annotations__Úbool© r)   r'   r;   r;   Q   sN   € € € € € € ðð ð ÐÐÑØÐÐÑØÐÐÑØÐÐÑÐÐr)   r;   F)Útotalc            $       ó¤  — e Zd Zej        ZeZeZ	dddœZ
dZdZdZdZdZdZdZdZdZdZeZ	 	 	 d%dd	d
edddededz  dedd	fd„Z	 d&dd	dedd	fd„Zded	         deded
edddedededededeee         z  dz  deee         z  dz  dededz  dededz  dedz  def$d „Z	 d'd!d"d#e ee!eef                  z  dz  dz  dee"e#e f                  fd$„Z$dS )(ÚDPTImageProcessori€  r,   TFgp?r+   NÚimager   ÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚ	antialiasr<   r   r   c                 óÖ   — |j         r|j        s$t          d|                     ¦   «         › �¦  «        ‚t	          ||j         |j        f||¬¦  «        }t          j        | ||||¬¦  «        S )a<  
        Resize an image to `(size["height"], size["width"])`.

        Args:
            image (`torch.Tensor`):
                Image to resize.
            size (`SizeDict`):
                Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
            interpolation (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`):
                `InterpolationMode` filter to use when resizing the image e.g. `InterpolationMode.BICUBIC`.
            antialias (`bool`, *optional*, defaults to `True`):
                Whether to use antialiasing when resizing the image
            ensure_multiple_of (`int`, *optional*):
                If `do_resize` is `True`, the image is resized to a size that is a multiple of this value
            keep_aspect_ratio (`bool`, *optional*, defaults to `False`):
                If `True`, and `do_resize` is `True`, the image is resized to the largest possible size such that the aspect ratio is preserved.

        Returns:
            `torch.Tensor`: The resized image.
        zDThe size dictionary must contain the keys 'height' and 'width'. Got )r   r   r   )rL   rM   )r-   r.   Ú
ValueErrorÚkeysr9   r   Úresize)ÚselfrJ   rK   rL   rM   r<   r   r   s           r'   rQ   zDPTImageProcessor.resizez   s…   € ð: Œ{ð 	s $¤*ð 	sÝÐqÐdh×dmÒdmÑdoÔdoÐqÐqÑrÔrÐrå2ØØœ d¤jÐ1Ø/Ø'ð	
ñ 
ô 
ˆõ "Ô(¨¨u°kÈHÐ`iÐjÑjÔjÐjr)   r=   c                 óž   — |j         dd…         \  }}d„ } |||¦  «        \  }} |||¦  «        \  }}	|||	|f}
t          j        ||
¦  «        S )a„  
        Center pad a batch of images to be a multiple of `size_divisor`.

        Args:
            image (`torch.Tensor`):
                Image to pad.  Can be a batch of images of dimensions (N, C, H, W) or a single image of dimensions (C, H, W).
            size_divisor (`int`):
                The width and height of the image will be padded to a multiple of this number.
        r*   Nc                 ó\   — t          j        | |z  ¦  «        |z  }|| z
  }|dz  }||z
  }||fS )Nr   )r    r"   )rK   r=   Únew_sizeÚpad_sizeÚpad_size_leftÚpad_size_rights         r'   Ú_get_padz-DPTImageProcessor.pad_image.<locals>._get_pad²   sB   € Ý”y ¨Ñ!4Ñ5Ô5¸ÑDˆHØ $‘ˆHØ$¨™MˆMØ%¨Ñ5ˆNØ  .Ð0Ð0r)   )r/   ÚtvFÚpad)rR   rJ   r=   r-   r.   rY   Úpad_topÚ
pad_bottomÚpad_leftÚ	pad_rightÚpaddings              r'   Ú	pad_imagezDPTImageProcessor.pad_image¢   su   € ð œ B C CÔ(‰ˆ�ð	1ð 	1ð 	1ð '˜h v¨|Ñ<Ô<Ñˆ�Ø&˜h u¨lÑ;Ô;Ñˆ�)Ø˜W i°Ð<ˆÝŒw�u˜gÑ&Ô&Ð&r)   Úimagesr>   Ú	do_resizeÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_padÚdisable_groupingc           	      ó  — |r|                       |¦  «        }t          ||¬¦  «        \  }}i }|                     ¦   «         D ]&\  }}|r|                      |||||¬¦  «        }|||<   Œ't	          ||¦  «        }t          ||¬¦  «        \  }}i }|                     ¦   «         D ]T\  }}|r|                      ||¦  «        }|                      |||	|
||¦  «        }|r|                      ||¦  «        }|||<   ŒUt	          ||¦  «        }|S )N)rl   )rJ   rK   rL   r<   r   )Úreduce_labelr   ÚitemsrQ   r	   Úcenter_cropÚrescale_and_normalizera   )rR   rb   r>   rc   rK   rL   rd   re   rf   rg   rh   ri   rj   r   r<   rk   r=   rl   ÚkwargsÚgrouped_imagesÚgrouped_images_indexÚresized_images_groupedr/   Ústacked_imagesÚresized_imagesÚprocessed_images_groupedÚprocessed_imagess                              r'   Ú_preprocesszDPTImageProcessor._preprocess¾   sx  € ð* ð 	/Ø×&Ò& vÑ.Ô.ˆFõ 0EÀVÐ^nÐ/oÑ/oÔ/oÑ,ˆÐ,Ø!#ÐØ%3×%9Ò%9Ñ%;Ô%;ð 		;ð 		;Ñ!ˆE�>Øð Ø!%§¢Ø(ØØ%Ø'9Ø&7ð "-ñ "ô "�ð -;Ð" 5Ñ)Ð)Ý'Ð(>Ð@TÑUÔUˆõ 0EÀ^ÐfvÐ/wÑ/wÔ/wÑ,ˆÐ,Ø#%Ð Ø%3×%9Ò%9Ñ%;Ô%;ð 		=ð 		=Ñ!ˆE�>Øð MØ!%×!1Ò!1°.À)Ñ!LÔ!L�à!×7Ò7Ø 
¨N¸LÈ*ÐV_ñô ˆNð ð NØ!%§¢°ÀÑ!MÔ!M�Ø.<Ð$ UÑ+Ð+å)Ð*BÐDXÑYÔYÐàÐr)   Úoutputsr   Útarget_sizesc                 óæ  — t          | d¦  «         |j        }|�/t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚g }|€dgt          |¦  «        z  n|}t	          ||¦  «        D ]~\  }}|�`t
          j        j                             | 	                    d¦  «         	                    d¦  «        |dd¬¦  «         
                    ¦   «         }|                     d	|i¦  «         Œ|S )
aÊ  
        Converts the raw output of [`DepthEstimatorOutput`] into final depth predictions and depth PIL images.
        Only supports PyTorch.

        Args:
            outputs ([`DepthEstimatorOutput`]):
                Raw outputs of the model.
            target_sizes (`TensorType` or `List[Tuple[int, int]]`, *optional*):
                Tensor of shape `(batch_size, 2)` or list of tuples (`Tuple[int, int]`) containing the target size
                (height, width) of each image in the batch. If left to None, predictions will not be resized.

        Returns:
            `List[Dict[str, TensorType]]`: A list of dictionaries of tensors representing the processed depth
            predictions.
        ÚtorchNz]Make sure that you pass in as many target sizes as the batch dimension of the predicted depthr   r+   ÚbicubicF)rK   ÚmodeÚalign_cornersÚpredicted_depth)r   r‚   ÚlenrO   Úzipr~   Únnr   ÚinterpolateÚ	unsqueezeÚsqueezeÚappend)rR   r{   r|   r‚   ÚresultsÚdepthÚtarget_sizes          r'   Úpost_process_depth_estimationz/DPTImageProcessor.post_process_depth_estimationø   s  € õ( 	˜$ Ñ(Ô(Ð(à!Ô1ˆàÐ$­3¨Ñ+?Ô+?Å3À|ÑCTÔCTÒ+TÐ+TÝØoñô ð ð ˆØ8DÐ8L˜�v¥ OÑ 4Ô 4Ñ4Ð4ÐR^ˆÝ"% o°|Ñ"DÔ"Dð 	7ð 	7ÑˆE�;ØÐ&ÝœÔ+×7Ò7Ø—O’O AÑ&Ô&×0Ò0°Ñ3Ô3¸+ÈIÐejð 8ñ ô ç’'‘)”)ð ð �NŠNÐ-¨uÐ5Ñ6Ô6Ð6Ð6àˆr)   )Tr+   F)r+   r   )%r?   r@   rA   r   ÚBICUBICrL   r
   ri   r   rj   rK   rc   rf   rh   rk   rg   r<   r   re   rd   r>   r;   Úvalid_kwargsr   rE   rC   rQ   ra   ÚlistÚfloatr   rz   r   ÚtupleÚdictÚstrr�   rF   r)   r'   rI   rI   e   s~  € € € € € à!Ô)€HØ'€JØ%€IØ CÐ(Ð(€DØ€IØ€JØ€LØ€FØ€NØÐØÐð €IØ€NØÐà*€Lð Ø)*Ø"'ð&kð &kàð&kð ð&kð Lð	&kð
 ð&kð   $™Jð&kð  ð&kð 
ð&kð &kð &kð &kðV ð'ð 'àð'ð ð'ð 
ð	'ð 'ð 'ð 'ð88 à�^Ô$ð8 ð ð8 ð ð	8 ð
 ð8 ð Lð8 ð ð8 ð ð8 ð ð8 ð ð8 ð ð8 ð ˜D œKÑ'¨$Ñ.ð8 ð ˜4 œ;Ñ&¨Ñ-ð8 ð  ð8 ð   $™Jð8 ð  ð!8 ð" ˜D‘jð#8 ð$  ™+ð%8 ð( 
ð)8 ð 8 ð 8 ð 8 ðz JNð'ð 'à'ð'ð ! 4¨¨c°3¨h¬Ô#8Ñ8¸4Ñ?À$ÑFð'ð 
ˆd�3˜
�?Ô#Ô	$ð	'ð 'ð 'ð 'ð 'ð 'r)   rI   )%r    Úcollections.abcr   Útypingr   r~   Úimage_processing_backendsr   Úimage_processing_baser   Úimage_transformsr   r	   Úimage_utilsr
   r   r   r   Úprocessing_utilsr   Úutilsr   r   r   Úbeit.image_processing_beitr   Úmodeling_outputsr   Útorchvision.transforms.v2r   rZ   rC   rE   r9   r;   rI   Ú__all__rF   r)   r'   ú<module>r¡      sò  ðð  €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø  Ð  Ð  Ð  Ð  Ð  à €€€à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ Eðð ð ð ð ð ð ð ð ð ð ð ð -Ð ,Ð ,Ð ,Ð ,Ð ,Ø BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BØ ;Ð ;Ð ;Ð ;Ð ;Ð ;ð ð 9Ø8Ð8Ð8Ð8Ð8Ð8à 7Ð 7Ð 7Ð 7Ð 7Ð 7ð$8Øð$8à�x ”}Ñ$ð$8ð ð$8ð ð	$8ð
 ð$8ð $8ð $8ð $8ðNð ð ð ð ˜l°%ð ñ ô ð ð( ðyð yð yð yð yÐ*ñ yô yñ „ðyðx Ð
€€€r)   