
    fTht                         S SK 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)    )ListUnion   )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U 4S jrSS\\\\   S\S   4   4U 4S j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).
c                 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      _/var/www/auris/envauris/lib/python3.13/site-packages/transformers/pipelines/depth_estimation.pyr    DepthEstimationPipeline.__init__2   s.    $)&)$)FG    inputszImage.Imagec                 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   __call__)r   r!   r   r   s      r   r&    DepthEstimationPipeline.__call__7   sB    D vZZ)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   r)   
parametersr   preprocess_paramss        r   _sanitize_parameters,DepthEstimationPipeline._sanitize_parameters_   sG    +2i(j$''I,C+5i+@i( "b((r    c                     [        X5      nU R                  XR                  S9nU R                  S:X  a  UR                  U R                  5      nUR
                  S S S2   US'   U$ )N)r#   return_tensorspttarget_size)r   image_processor	frameworktotorch_dtypesize)r   imager)   model_inputss       r   
preprocess"DepthEstimationPipeline.preprocessg   s`    5*++5+X>>T!'??4+;+;<L&+jj2&6]#r    c                 T    UR                  S5      nU R                  " S0 UD6nX#S'   U$ )Nr4    )r$   model)r   r;   r4   model_outputss       r   _forward DepthEstimationPipeline._forwardo   s1    "&&}5

2\2'2m$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$ )Nr4   predicted_depth   uint8)rE   depthr   r   )r5   post_process_depth_estimationdetachcpunumpyminmaxr   	fromarrayastypeappendlen)r   rA   outputsformatted_outputsoutputrH   s         r   postprocess#DepthEstimationPipeline.postprocessu   s    &&DD =)*	
 F,-446::<BBDEYY[(UYY[599;-FGEOOUS[$8$8$ABE$$@Q9R]b%cd  (+7|q'8 #O>OOr    r?   )N)NN)__name__
__module____qualname____firstlineno____doc__r   r   strr   r&   r.   r<   rB   rV   __static_attributes____classcell__)r   s   @r   r   r      sR    0H
&2uS$s)]DDW%WX &2 &2P)P Pr    r   N)typingr   r   utilsr   r   r   r	   r
   baser   r   PILr   image_utilsr   models.auto.modeling_autor   
get_loggerrX   loggerr   r?   r    r   <module>rh      sq      5 (T			H	% ,FGlPh lP HlPr    