Ë
    ÛÓ^jH,  ã            
       ó  — 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$y)é    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 )Nc                 ó¬   — t        | |z  «      |z  }|� ||kD  rt        j                  | |z  «      |z  }||k  rt        j                  | |z  «      |z  }|S ©N)ÚroundÚmathÚfloorÚceil)Úvalr   Úmin_valÚmax_valÚxs        ún/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/dpt/modular_dpt.pyÚconstrain_to_multiple_ofz>get_resize_output_image_size.<locals>.constrain_to_multiple_of0   s[   € Ü�#˜‘.Ó! 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Ñ 1°"°#Ð 6Ñ€L�+Ø"-Ñ€M�<ð ! <Ñ/€LØ Ñ,€Káäˆq�;‰Ó¤# a¨,Ñ&6Ó"7Ò7à&‰Lð 'ˆKá)¨,¸Ñ*EÐPXÔY€JÙ(¨°{Ñ)BÈXÔV€Iä˜:¨YÔ7Ð7r)   c                   ó:   — e Zd ZU dZeed<   eed<   eed<   eed<   y)Ú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   s!   … ñð ÓØÓØÓØÔ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$y)(ÚDPTImageProcessori€  r,   TFgp?r+   NÚimager   ÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚ	antialiasr<   r   r   c                 óè   — |j                   r|j                  st        d|j                  «       › �«      ‚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   sn   € ð: �{Š{ $§*¢*ÜÐcÐdh×dmÑdmÓdoÐcpÐqÓrÐrä2ØØŸ™ d§j¡jÐ1Ø/Ø'ô	
ˆô "×(Ñ(¨¨u°kÈHÐ`iÔ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²   sA   € Ü—y‘y ¨Ñ!4Ó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¢   s`   € ð Ÿ™ B CÐ(‰ˆ�ò	1ñ ' v¨|Ó<Ñˆ�Ù& u¨lÓ;Ñˆ�)Ø˜W i°Ð<ˆÜ�w‰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| j                  |«      }t        ||¬«      \  }}i }|j                  «       D ]"  \  }}|r| j                  |||||¬«      }|||<   Œ$ t	        ||«      }t        ||¬«      \  }}i }|j                  «       D ]H  \  }}|r| j                  ||«      }| j                  |||	|
||«      }|r| j                  ||«      }|||<   ŒJ t	        ||«      }|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¾   s5  € ñ* Ø×&Ñ& vÓ.ˆFô 0EÀVÐ^nÔ/oÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ó%;ò 		;Ñ!ˆE�>ÙØ!%§¡Ø(ØØ%Ø'9Ø&7ð "-ó "�ð -;Ð" 5Ò)ð		;ô (Ð(>Ð@TÓUˆô 0EÀ^ÐfvÔ/wÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ó%;ò 		=Ñ!ˆE�>ÙØ!%×!1Ñ!1°.À)Ó!L�à!×7Ñ7Ø 
¨N¸LÈ*ÐV_óˆNñ Ø!%§¡°ÀÓ!M�Ø.<Ð$ UÒ+ð		=ô *Ð*BÐDXÓYÐàÐr)   Úoutputsr   Útarget_sizesc                 ó¬  — t        | d«       |j                  }|�"t        |«      t        |«      k7  rt        d«      ‚g }|€dgt        |«      z  n|}t	        ||«      D ]s  \  }}|�Yt
        j                  j                  j                  |j                  d«      j                  d«      |dd¬«      j                  «       }|j                  d	|i«       Œu |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Ñ1ˆàÐ$¬3¨Ó+?Ä3À|ÓCTÒ+TÜØoóð ð ˆØ8DÐ8L˜�v¤ OÓ 4Ò4ÐR^ˆÜ"% o°|Ó"Dò 	7ÑˆE�;ØÐ&ÜŸ™×+Ñ+×7Ñ7Ø—O‘O AÓ&×0Ñ0°Ó3¸+ÈIÐejð 8ó ç‘'“)ð ð �N‰NÐ-¨uÐ5Õ6ð	7ð ˆ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ð Lð	&kð
 ð&kð   $™Jð&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 ð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ß E÷ó õ -ß BÑ BÝ ;ñ Ý8å 7ð$8Øð$8à�x ‘}Ñ$ð$8ð ð$8ð ð	$8ð
 ó$8ôN˜l°%õ ð( ôyÐ*ó yó ðyðx Ð
�r)   