o
    ॵi                     @   s   d dl mZmZmZ d dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ e Zejeje
jdG dd deZdS )    )AnyDictUnionN)	Pipelines)
OutputKeys)InputModelPipeline)	PIPELINES)	LoadImage)Tasks)depth_to_color)
get_logger)module_namec                       s   e Zd Zdef fddZdedeeef fddZdeeef deeef fdd	Z	d
eeef deeef fddZ
  ZS )ImageDepthEstimationPipelinemodelc                    s$   t  jdd|i| td dS )z
        use `model` to create a image depth estimation pipeline for prediction
        Args:
            model: model id on modelscope hub.
        r   z%depth estimation model, pipeline initN )super__init__loggerinfo)selfr   kwargs	__class__r   k/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/pipelines/cv/image_depth_estimation_pipeline.pyr      s   z%ImageDepthEstimationPipeline.__init__inputreturnc                 C   sP   t |tj}d\}}t|||g}|dddd }|d }d|i}|S )N)i  i     r      g     o@)N.imgs)r   convert_to_ndarrayastypenpfloat32cv2resize	transpose)r   r   imgHWr    datar   r   r   
preprocess#   s   z'ImageDepthEstimationPipeline.preprocessc                 C   s   | j |}|S N)r   	inference)r   r   resultsr   r   r   forward-   s   z$ImageDepthEstimationPipeline.forwardinputsc                 C   sR   | j |}|tj }t|tjr|  	 
 }t|}tj|tj|i}|S r-   )r   postprocessr   DEPTHS
isinstancetorchTensordetachcpusqueezenumpyr   DEPTHS_COLOR)r   r1   r/   depthsdepths_coloroutputsr   r   r   r2   1   s   
z(ImageDepthEstimationPipeline.postprocess)__name__
__module____qualname__strr   r   r   r   r,   r0   r2   __classcell__r   r   r   r   r      s
    
"
*r   )typingr   r   r   r%   r:   r#   PILr5   modelscope.metainfor   modelscope.outputsr   modelscope.pipelines.baser   r   r	   modelscope.pipelines.builderr
   modelscope.preprocessorsr   modelscope.utils.constantr   modelscope.utils.cv.image_utilsr   modelscope.utils.loggerr   r   register_moduleimage_depth_estimationr   r   r   r   r   <module>   s$   