ó
    ‰Ž¡jã  ã                   óð   • S SK JrJrJr  SSKJrJrJrJrJ	r	  SSK
JrJr  \" 5       (       a  S SKJr  SSKJr  \" 5       (       a  SSKJr  \R&                  " \5      r\" \" S	S
95       " S S\5      5       rg)é    )ÚAnyÚUnionÚoverloadé   )Úadd_end_docstringsÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backendsé   )ÚPipelineÚbuild_pipeline_init_args)ÚImage)Ú
load_image)Ú(MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMEST)Úhas_image_processorc            
       ó&  ^ • \ rS rSrSrSrSrSrSrU 4S jr	\
S\\S4   S\S	\\\4   4S
 j5       r\
S\\\S4      S\S	\\\\4      4S j5       rS\\\\   S\S   4   S\S	\\\4   \\\\4      -  4U 4S jjrSS jrSS jrS rS rSrU =r$ )ÚDepthEstimationPipelineé   a`  
Depth estimation pipeline using any `AutoModelForDepthEstimation`. This pipeline predicts the depth of an image.

Example:

```python
>>> from transformers import pipeline

>>> depth_estimator = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
>>> output = depth_estimator("http://images.cocodataset.org/val2017/000000039769.jpg")
>>> # This is a tensor with the values being the depth expressed in meters for each pixel
>>> output["predicted_depth"].shape
torch.Size([1, 384, 384])
```

Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)


This depth estimation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"depth-estimation"`.

See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=depth-estimation).
FTc                 óh   >• [         TU ]  " U0 UD6  [        U S5        U R                  [        5        g )NÚvision)ÚsuperÚ__init__r   Úcheck_model_typer   )ÚselfÚargsÚkwargsÚ	__class__s      €ÚµC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/pipelines/depth_estimation.pyr   Ú DepthEstimationPipeline.__init__7   s.   ø€ Ü‰Ò˜$Ð) &Ò)Ü˜$ Ô)Ø×ÑÔFÕGó    ÚinputszImage.Imager   Úreturnc                 ó   • g ©N© ©r   r"   r   s      r   Ú__call__Ú DepthEstimationPipeline.__call__<   s   € Ø\_r!   c                 ó   • g r%   r&   r'   s      r   r(   r)   ?   s   € Øhkr!   c                 óp   >• SU;   a  UR                  S5      nUc  [        S5      e[        TU ]  " U40 UD6$ )a(  
Predict the depth(s) of the image(s) passed as inputs.

Args:
    inputs (`str`, `list[str]`, `PIL.Image` or `list[PIL.Image]`):
        The pipeline handles three types of images:

        - A string containing a http link pointing to an image
        - A string containing a local path to an image
        - An image loaded in PIL directly

        The pipeline accepts either a single image or a batch of images, which must then be passed as a string.
        Images in a batch must all be in the same format: all as http links, all as local paths, or all as PIL
        images.
    parameters (`Dict`, *optional*):
        A dictionary of argument names to parameter values, to control pipeline behaviour.
        The only parameter available right now is `timeout`, which is the length of time, in seconds,
        that the pipeline should wait before giving up on trying to download an image.
    timeout (`float`, *optional*, defaults to None):
        The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
        the call may block forever.

Return:
    A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
    dictionary, if the input is a list of several images, will return a list of dictionaries corresponding to
    the images.

    The dictionaries contain the following keys:

    - **predicted_depth** (`torch.Tensor`) -- The predicted depth by the model as a `torch.Tensor`.
    - **depth** (`PIL.Image`) -- The predicted depth by the model as a `PIL.Image`.
ÚimageszECannot call the depth-estimation pipeline without an inputs argument!)ÚpopÚ
ValueErrorr   r(   )r   r"   r   r   s      €r   r(   r)   B   sB   ø€ ðH �vÓØ—Z‘Z Ó)ˆFØ‰>ÜÐdÓeÐeÜ‰wÒ Ñ1¨&Ñ1Ð1r!   c                 ód   • 0 nUb  XS'   [        U[        5      (       a  SU;   a  US   US'   U0 0 4$ )NÚtimeout)Ú
isinstanceÚdict)r   r0   Ú
parametersr   Úpreprocess_paramss        r   Ú_sanitize_parametersÚ,DepthEstimationPipeline._sanitize_parametersl   sG   € ØÐØÑØ+2˜iÑ(Ü�j¤$×'Ñ'¨I¸Ó,CØ+5°iÑ+@Ð˜iÑ(Ø  " bÐ(Ð(r!   c                 óœ   • [        X5      nU R                  USS9nUR                  U R                  5      nUR                  S S S2   US'   U$ )NÚpt)r,   Úreturn_tensorséÿÿÿÿÚtarget_size)r   Úimage_processorÚtoÚdtypeÚsize)r   Úimager0   Úmodel_inputss       r   Ú
preprocessÚ"DepthEstimationPipeline.preprocesst   sP   € Ü˜5Ó*ˆØ×+Ñ+°5ÈÐ+ÐNˆØ#—‘ t§z¡zÓ2ˆØ&+§j¡j±°2°Ñ&6ˆ�]Ñ#ØÐr!   c                 óT   • UR                  S5      nU R                  " S0 UD6nX#S'   U$ )Nr;   r&   )r-   Úmodel)r   rA   r;   Úmodel_outputss       r   Ú_forwardÚ DepthEstimationPipeline._forward{   s1   € Ø"×&Ñ& }Ó5ˆØŸ
š
Ñ2 \Ñ2ˆØ'2�mÑ$ØÐr!   c                 óÈ  • U R                   R                  UUS   /5      n/ nU H¥  nUS   R                  5       R                  5       R	                  5       nXUR                  5       -
  UR                  5       UR                  5       -
  -  n[        R                  " US-  R                  S5      5      nUR                  US   US.5        M§     [        U5      S:X  a  US   $ U$ )Nr;   Úpredicted_depthéÿ   Úuint8)rJ   Údepthr   r   )r<   Úpost_process_depth_estimationÚdetachÚcpuÚnumpyÚminÚmaxr   Ú	fromarrayÚastypeÚappendÚlen)r   rF   ÚoutputsÚformatted_outputsÚoutputrM   s         r   ÚpostprocessÚ#DepthEstimationPipeline.postprocess�   sÚ   € Ø×&Ñ&×DÑDØð ˜=Ñ)Ð*ó	
ˆð ÐÛˆFØÐ,Ñ-×4Ñ4Ó6×:Ñ:Ó<×BÑBÓDˆEØŸY™Y›[Ñ(¨U¯Y©Y«[¸5¿9¹9»;Ñ-FÑGˆEÜ—O’O U¨S¡[×$8Ñ$8¸Ó$AÓBˆEà×$Ñ$¸Ð@QÑ9RÐ]bÑ%cÖdñ ô (+¨7£|°qÓ'8Ð  Ñ#ÐOÐ>OÐOr!   r&   )NNr%   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r   r   Ústrr   r2   r(   Úlistr5   rB   rG   r[   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s  ø† ñð0 €OØ ÐØ#ÐØ€OõHð
 Ø_˜u S¨-Ð%7Ñ8Ð_ÀCÐ_ÈDÐQTÐVYÐQYÉNÓ_ó Ø_àØk˜t E¨#¨}Ð*<Ñ$=Ñ>ÐkÈ#ÐkÐRVÐW[Ð\_ÐadÐ\dÑWeÑRfÓkó Økð(2Ø˜C  c¡¨M¸4ÀÑ;NÐNÑOð(2Ø[^ð(2à	ˆc�3ˆh‰˜$˜t C¨ H™~Ñ.Ñ	.÷(2ôT)ôò÷Pð Pr!   r   N)Útypingr   r   r   Úutilsr   r   r	   r
   r   Úbaser   r   ÚPILr   Úimage_utilsr   Úmodels.auto.modeling_autor   Ú
get_loggerr]   Úloggerr   r&   r!   r   Ú<module>rr      st   ðß 'Ñ '÷õ ÷ 5ñ ×ÑÝå(á×ÑÝTà	×	Ò	˜HÓ	%€ñ Ñ,ÀÑFÓGôxP˜hó xPó HñxPr!   