
    =pj                         S SK JrJrJrJrJrJr  S SKrSSK	J
r
  SSKJrJr  SSKJr  SSKJr  S	S
KJr  S	SKJr  \\\4   r\R2                   " S S\5      5       r\
" S5       " S S\5      5       rg)    )AnyDictListOptionalTupleUnionN   )pipeline_requires_extra   )	HPIConfigPaddlePredictorOption)	KptResult)	benchmark   )(AutoParallelImageSimpleInferencePipeline)BasePipelinec                   n  ^  \ rS rSrSrSSSSSSS.S\S\\   S\\   S	\\\\4      S
\\	   S\
S\\\\\4   \4      SS4U 4S jjjr SS\\\R                   4   S\S\\R                   \R                   4   4S jjr SS\\\\   \R                   \\R                      4   S\\   S\4S jjrSrU =r$ )_KeypointDetectionPipeline   zKeypoint Detection pipelineNFdeviceengineengine_config	pp_optionuse_hpip
hpi_configconfigr   r   r   r   r   r   returnc          
        > [         TU ]  " S
UUUUUUS.UD6  US   S   n	0 n
SU l        SU	;   a  U	S   U
S'   U	S   U l        SU	;   a  U	S   U
S'   U R                  " U	40 U
D6U l        US   S   n	0 n
SU	;   a  U	S   U
S'   S	U	;   a  U	S	   U
S	'   U R                  " U	40 U
D6U l        U R
                  R                  U l        g)a  Initializes the keypoint detection pipeline.

Args:
    config (Dict): Configuration dictionary containing model and other parameters.
    device (Optional[str], optional): The device to use for prediction. Defaults to `None`.
    engine (Optional[str], optional): Inference engine. Defaults to `None`.
    engine_config (Optional[Dict[str, Any]], optional): Engine-specific config. Defaults to `None`.
    pp_option (Optional[PaddlePredictorOption], optional): Paddle predictor options.
        Defaults to `None`.
    use_hpip (bool, optional): Whether to use HPIP. Defaults to `False`.
    hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional):
        HPIP configuration. Defaults to `None`.
r   
SubModulesObjectDetectionN	thresholdimgszKeypointDetectionflipuse_udp )super__init__det_thresholdcreate_model	det_model	kpt_model
input_sizekpt_input_size)selfr   r   r   r   r   r   r   kwargs	model_cfgmodel_kwargs	__class__s              s/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/keypoint_detection/pipeline.pyr)   #_KeypointDetectionPipeline.__init__!   s   2 	 	
'!	
 	
 <():;	!)#(1+(>L%!*;!7Di$-g$6L!**9EE <()<=	Y#,V#4L 	!&/	&:L#**9EE"nn77    bboxpaddingc                    USS u  p4pV[         R                  " X5-   XF-   /5      S-  nU R                  S   U R                  S   -  nXS-
  Xd-
  pXU
-  :  a  X-  n
OXU
-  :  a  X-  n	[         R                  " X/5      U-  nX{4$ )aE  
Convert bounding box from (x1, y1, x2, y2) to center and scale.

Args:
    bbox (Union[Number, np.ndarray]): The bounding box coordinates (x1, y1, x2, y2).
    padding (float): The padding factor to adjust the scale of the bounding box.

Returns:
    Tuple[np.ndarray, np.ndarray]: The center and scale of the bounding box.
Nr	   g      ?r      )nparrayr/   )r0   r8   r9   x1y1x2y2centeraspect_ratiowhscales               r5   _box_xyxy2cs'_KeypointDetectionPipeline._box_xyxy2csZ   s     bq27BG,-3 **1-0C0CA0FFw1a A!! A! 7*}r7   inputr*   c           
   +   x  #    Uc  U R                   OUnU R                  XS9 H  nUS   US   peXe/ S.nUS    Hk  nU R                  US   5      u  p[        U R	                  UU	U
S.5      5      S	   nUS   R                  US   US
   US   S	   S   US   S	   S   S.5        Mm     [        U5      v   M     g7f)a  Predicts image classification results for the given input.

Args:
    input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
    det_threshold (float): The detection threshold. Defaults to `None`.
    **kwargs: Additional keyword arguments that can be passed to the function.

Returns:
    KptResult: The predicted KeyPoint Detection results.
N)r"   	input_img
input_path)rL   rK   boxesrM   
coordinate)imgrB   rF   r   scorekpts	keypoints	kpt_score)rN   	det_scorerR   rS   )r*   r,   rG   listr-   appendr   )r0   rI   r*   r1   det_resori_imgimg_pathsingle_img_resboxrB   rF   kpt_ress               r5   predict"_KeypointDetectionPipeline.predictv   s       /<.C**~~e~EG ' 4gl6KX,4UWXNw' $ 1 1#l2C DNN#*&,%*  w'..&),&7%(\%,V_Q%7%D%,V_Q%7%D	 (& N++- Fs   B8B:)r,   r*   r/   r-   )g      ?N)__name__
__module____qualname____firstlineno____doc__r   r   strr   r   boolr   r   r)   Numberr<   ndarrayfloatr   rG   r   r   r]   __static_attributes____classcell__)r4   s   @r5   r   r      s7   % !% $2659AE7878 	78
 78  S#X/78 1278 78 U4S>9#<=>78 
78 78t AE&"**,-8=	rzz2::%	&> *.',S$s)RZZbjj1AAB',  ',
 
', ',r7   r   cvc                   .    \ rS rSrSr\S 5       rS rSrg)KeypointDetectionPipeline   human_keypoint_detectionc                     [         $ r_   )r   )r0   s    r5   _pipeline_cls'KeypointDetectionPipeline._pipeline_cls   s    ))r7   c                 2    US   S   R                  SS5      $ )Nr    r!   
batch_sizer;   )get)r0   r   s     r5   _get_batch_size)KeypointDetectionPipeline._get_batch_size   s     l#$56::<KKr7   r'   N)	r`   ra   rb   rc   entitiespropertyrr   rw   rj   r'   r7   r5   rn   rn      s    )H* *Lr7   rn   )typingr   r   r   r   r   r   numpyr<   
utils.depsr
   modelsr   r    models.keypoint_detection.resultr   utils.benchmarkr   	_parallelr   baser   intri   rg   time_methodsr   rn   r'   r7   r5   <module>r      sy    ; :  2 6 9 ( @ 	sEz	 , , ,D L H L Lr7   