
    9i                     L   S SK Jr  S SKJrJrJrJr  S SKrS SK	r
S SKrS SKrS SKJr  S SKJr  S SKJrJ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 J!r!  S SK"J#r#  S SK$J%r%  \%" 5       r&\RN                  " \!RP                  \RP                  S9 " S S\5      5       r)g)    N)AnyDictListUnion)	Pipelines)Model)ScrfdDetectSCRFDPreprocessor)
OutputKeys)InputPipeline)	PIPELINES)	LoadImage)Config)	ModelFileTasks)Image)
get_logger)module_namec                      ^  \ rS rSrS\4U 4S jjrS\\\\   4   4U 4S jjr	S\S\
\\4   4S jrS\
\\4   S\
\\4   4S jrS	\
\\4   S\
\\4   4S
 jrSrU =r$ )FaceDetectionPipeline   modelc                   > [         TU ]  " SSU0UD6  [        R                  " U[        R
                  5      n[        R                  " U5      n[        USS5      nUc  [        SSU0UD6nOK[        U R                  [        5      (       d   S5       eU R                  R                  U R                  5      nU R                  c  [!        5       U l        X`l        g)z
use `model` to create a face detection pipeline for prediction
Args:
    model (`str` or `Model`): model_id or `ScrfdDetect` or `TinyMogDetect` model.
    preprocessor(`Preprocessor`, *optional*,  defaults to None): `SCRFDPreprocessor`.
r   N	model_dirz model object is not initialized. )super__init__ospjoinr   CONFIGURATIONr   	from_filegetattrr	   
isinstancer   r   todevicepreprocessorr
   detector)selfr   kwargsconfig_pathcfg	cfg_modelr(   	__class__s          o/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/face_detection_pipeline.pyr   FaceDetectionPipeline.__init__   s     	/u//hhui&=&=>{+C$/	"=U=f=Hdjj#% % I&HI %zz}}T[[1H $ 1 3D     inputc                 &   > [         TU ]  " U40 UD6$ )a>  
Detect objects (bounding boxes or keypoints) in the image(s) passed as inputs.

Args:
    input (`Image` or `List[Image]`):
        The pipeline handles three types of images:

        - A string containing an HTTP(S) 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. Images in a batch must all be in the
        same format.

Return:
    A dictionary of result or a list of dictionary of result. If the input is an image, a dictionary
    is returned. If input is a list of image, a list of dictionary is returned.

    The dictionary contain the following keys:

    - **scores** (`List[float]`) -- The detection score for each card in the image.
    - **boxes** (`List[float]) -- The bounding boxe [x1, y1, x2, y2] of detected objects in in image's
        original size.
    - **keypoints** (`List[Dict[str, int]]`, optional) -- The corner kepoint [x1, y1, x2, y2, x3, y3, x4, y4]
        of detected object in image's original size.
)r   __call__)r)   r2   r*   r.   s      r/   r4   FaceDetectionPipeline.__call__6   s    6 w000r1   returnc                 (   U R                  U5      nSU;   az  SSKJnJn  U" U/SS9n[	        U R
                  R                  5       5      R                  (       a8  U" U[	        U R
                  R                  5       5      R                  /5      S   nU$ )N	img_metasr   )collatescatter   )samples_per_gpu)	r'   mmcv.parallelr9   r:   nextr   
parametersis_cudar&   )r)   r2   resultr9   r:   s        r/   
preprocess FaceDetectionPipeline.preprocessS   s    ""5) & 6fXq9FDJJ))+,44 "&tzz'<'<'>"?"F"F!GIIJLr1   c                 &    U R                   " S0 UD6$ )Nr   )r(   )r)   r2   s     r/   forwardFaceDetectionPipeline.forward`   s    }}%u%%r1   inputsc                     U$ )Nr   )r)   rG   s     r/   postprocess!FaceDetectionPipeline.postprocessc   s    r1   )r(   r'   )__name__
__module____qualname____firstlineno__strr   r   r   r   r4   r   r   rB   rE   rI   __static_attributes____classcell__)r.   s   @r/   r   r      s    !c !21eE4;$67 1: $sCx. &T#s(^ &S#X &$sCx. T#s(^  r1   r   )*os.pathpathr   typingr   r   r   r   cv2numpynpPILtorchmodelscope.metainfor   !modelscope.models.base.base_modelr   #modelscope.models.cv.face_detectionr	   r
   modelscope.outputsr   modelscope.pipelines.baser   r   modelscope.pipelines.builderr   modelscope.preprocessorsr   modelscope.utils.configr   modelscope.utils.constantr   r   $modelscope.utils.input_output_typingr   modelscope.utils.loggerr   loggerregister_moduleface_detectionr   r   r1   r/   <module>rh      s~     ) ) 
  
  ) 3 N ) 5 2 . * 6 6 .	 	i&>&>@IH I@Ir1   