o
    *j
                     @   s   d dl Z d dlZd dlmZmZm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 d dlmZmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ e ZejejejdG dd deZ dS )    N)AnyDictUnion)	Pipelines)infer)
OutputKeys)InputModelPipeline)	PIPELINES)	LoadImage)	ModelFileTasks)
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 )FaceLandmarkDetectionPipelinemodelc                    s~   t  jdd|i| tjdd}| }d|_t }tj	 r$dg}ndg}t
j|d}tj||d|d	| _td
 dS )z
        use `model` to create a image depth prediction pipeline for prediction
        Args:
            model: model id on modelscope hub.
        r   zEvaluation script)description	alignmentr   zpytorch_model.pklZpytorch)Zdl_framework
device_idsz/Face 2d landmark detection model, pipeline initN )super__init__argparseArgumentParser
parse_argsZconfig_namelisttorchcudais_availableospathjoinr   Z	Alignmentfldloggerinfo)selfr   kwargsparserargsr   Z
model_path	__class__r   x/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/cv/facial_68ldk_detection_pipeline.pyr      s   
z&FaceLandmarkDetectionPipeline.__init__inputreturnc                 C   s2   t d t|}t|d}d|i}t d |S )Nzstart preprocess)   r0   imagezfinish preprocess)printr   Zconvert_to_ndarraycv2resize)r'   r.   r1   datar   r   r-   
preprocess3   s   
z(FaceLandmarkDetectionPipeline.preprocessc                 C   s   t d |d }tj r|  }n| }d\}}}}t|| || d }|| d }	|| d }
t|t|	t|
}}	}
| j	|||	|
}t d |S )Nzstart inferr1   )r   r   r0   r0         zfinish infer)
r2   r   r   r    cpunumpymaxfloatr$   Zanalyze)r'   r.   r1   Zimage_npx1y1Zx2y2scaleZcenter_wZcenter_hresultsr   r   r-   forward?   s   
z%FaceLandmarkDetectionPipeline.forwardinputsc                 C   s   d|i}|S )NZ	landmarksr   )r'   rC   Zoutputsr   r   r-   postprocessV   s   z)FaceLandmarkDetectionPipeline.postprocess)__name__
__module____qualname__strr   r   r   r   r6   rB   rD   __classcell__r   r   r+   r-   r      s
    "*r   )!r   r!   typingr   r   r   r3   r:   npr   Zmodelscope.metainfor   Z+modelscope.models.cv.facial_68ldk_detectionr   Zmodelscope.outputsr   Zmodelscope.pipelines.baser   r	   r
   Zmodelscope.pipelines.builderr   Zmodelscope.preprocessorsr   Zmodelscope.utils.constantr   r   Zmodelscope.utils.loggerr   r%   Zregister_moduleZfacial_68ldk_detectionr   r   r   r   r-   <module>   s&   