
    <h                          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   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      _/var/www/html/shao/venv/lib/python3.13/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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   r0   
parametersr   preprocess_paramss        r   _sanitize_parameters,DepthEstimationPipeline._sanitize_parametersl   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   imager0   model_inputss       r   
preprocess"DepthEstimationPipeline.preprocesst   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$ )Nr;   r&   )r-   model)r   rB   r;   model_outputss       r   _forward DepthEstimationPipeline._forward|   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$ )Nr;   predicted_depth   uint8)rK   depthr   r   )r<   post_process_depth_estimationdetachcpunumpyminmaxr   	fromarrayastypeappendlen)r   rG   outputsformatted_outputsoutputrN   s         r   postprocess#DepthEstimationPipeline.postprocess   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&   )NNr%   )__name__
__module____qualname____firstlineno____doc___load_processor_load_image_processor_load_feature_extractor_load_tokenizerr   r   r   strr   r2   r(   listr5   rC   rH   r\   __static_attributes____classcell__)r   s   @r   r   r      s   0 O #OH
 _uS-%78_C_DQTVYQYN_ _ktE#}*<$=>k#kRVW[\_ad\dWeRfk k(2CcM4;NNO(2[^(2	tCH~tDcN33	4(2T)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>rs      st    ' '  5 (T			H	% ,FGyPh yP HyPr!   