+
    ÿäûj£0  ã                   óÖ   € R t ^ RIHt ^ RIHtHtHt ^ RIt^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHt . ROt ! R R]4      t ! R R4      t ! R R
]P.                  4      tR# )aî  Detect faces and five facial landmarks in RGB images with the pretrained YuNet network.

A detection is a row of 15 values: the box ``xmin, ymin, xmax, ymax`` and five ``(x, y)`` landmarks in the input
image's pixels, and the score.

Which class to use:

- Detect the faces of a batch of RGB images in :math:`[0, 255]`: :class:`FaceDetector`.
- Read the box, the landmarks and the score of its detections by name: :class:`FaceDetectorResult`, with
  :class:`FaceKeypoint` naming the landmarks.
)ÚEnum)ÚDictÚListÚOptionalN)Únn©Ú
rgb_to_bgr)Únms)ÚYuNet)ÚPriorBox)ÚdecodeÚFaceDetectorÚFaceDetectorResultÚFaceKeypointc                   ó.   € ] tR t^-tRt^ t^t^t^t^t	Rt
R# )r   a
  Name the five facial landmarks of a FaceDetector detection, left and right as the viewer sees them.

``FaceDetectorResult(dets).get_keypoint(FaceKeypoint.NOSE)`` returns the ``(x, y)`` pixel of that landmark for
each detection. ``EYE_LEFT`` and ``MOUTH_LEFT`` are the ones on the left of the image, the subject's right side
for a face that looks at the camera.

See Also:
    - :class:`FaceDetectorResult`: reads these landmarks, the box and the score of a detection.
    - :class:`FaceDetector`: returns the detections.

© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚEYE_LEFTÚ	EYE_RIGHTÚNOSEÚ
MOUTH_LEFTÚMOUTH_RIGHTÚ__static_attributes__r   ó    ÚYC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\contrib\face_detection.pyr   r   -   s"   † ñ
ð €HØ€IØ€DØ€JØ„Kr   c                   ó’  a € ] tR t^At o RtV 3R lR ltR V 3R lR llt]V 3R lR l4       t]V 3R	 lR
 l4       t	]V 3R lR l4       t
]V 3R lR l4       tV 3R lR lt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       tRtV tR# )!r   aÞ  Read the box, the five landmarks and the score of FaceDetector detections by name.

``result = FaceDetectorResult(dets)`` wraps the ``(N, 15)`` detections of one image from :class:`FaceDetector`,
or one ``(15,)`` row. Its properties (``xmin``, ``width``, ``top_left``, ``score``, ...) and
``result.get_keypoint(FaceKeypoint.NOSE)`` return ``(N,)`` values and ``(N, 2)`` points, or 0-d values and
``(2,)`` points for a single row. The box and the landmarks are in the pixels of the image the detector saw.

Args:
    data: the detections returned by :class:`FaceDetector`, one row of 15 values per face with
        shape ``(15,)`` or ``(N, 15)``: the box ``xmin, ymin, xmax, ymax``, five ``(x, y)`` landmarks
        (see :class:`FaceKeypoint`) and the score.

Raises:
    ValueError: If the last dimension of ``data`` is shorter than 15.

See Also:
    - :class:`FaceDetector`: returns the detections this reads.
    - :class:`FaceKeypoint`: names the landmarks for :meth:`get_keypoint`.

c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )é   ÚdataÚreturnN©ÚtorchÚTensor)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚFaceDetectorResult.__annotate__W   s   ø€ ÷ ñ ™UŸ\™\ð ¨dñ r   c                ót   € VP                   R,          ^8  d   \        RVP                    R24      hWn        R# )é   zCResult must come as a row of 15 values in its last dimension. Got: Ú.Néÿÿÿÿ)ÚshapeÚ
ValueErrorÚ_data)Úselfr"   s   &&r   Ú__init__ÚFaceDetectorResult.__init__W   s5   € Ø�:‰:�b�>˜BÔÜÐbÐcg×cmÑcmÐbnÐnoÐpÓqÐqØŽ
r   Nc                ór   <€ V ^8„  d   QhRS[ S[P                  ,          RS[ S[P                  ,          RR/# )r!   ÚdeviceÚdtyper#   r   )r   r%   r6   r7   )r'   r(   s   "€r   r)   r*   \   s5   ø€ ÷ ñ ™¡%§,¡,Õ/ð ¹xÉÏÉÕ?Tð Ð`tñ r   c                óH   € V P                   P                  WR7      V n         V # )z^Move the detections to ``device`` and cast them to ``dtype`` in place, and return this result.©r6   r7   )r1   Úto)r2   r6   r7   s   &&&r   r:   ÚFaceDetectorResult.to\   s   € à—Z‘Z—]‘]¨&�]Ó>ˆŒ
Øˆr   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r!   r#   r$   )r'   r(   s   "€r   r)   r*   b   ó   ø€ ÷ "ñ "‘e—l‘lñ "r   c                ó(   € V P                   R,          # )z'The bounding box top-left x-coordinate.©.é    ©r1   ©r2   s   &r   ÚxminÚFaceDetectorResult.xmina   ó   € ð �z‰z˜&Õ!Ð!r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   g   r>   r   c                ó(   € V P                   R,          # )z'The bounding box top-left y-coordinate.©.r,   rB   rC   s   &r   ÚyminÚFaceDetectorResult.yminf   rF   r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   l   r>   r   c                ó(   € V P                   R,          # )z+The bounding box bottom-right x-coordinate.).r!   rB   rC   s   &r   ÚxmaxÚFaceDetectorResult.xmaxk   rF   r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   q   r>   r   c                ó(   € V P                   R,          # )z+The bounding box bottom-right y-coordinate.).é   rB   rC   s   &r   ÚymaxÚFaceDetectorResult.ymaxp   rF   r   c                ó:   <€ V ^8„  d   QhRS[ RS[P                  /# )r!   Úkeypointr#   )r   r%   r&   )r'   r(   s   "€r   r)   r*   u   s   ø€ ÷ ñ ¡\ð ±e·l±lñ r   c                óÄ  € V\         P                  8X  d   V P                  R,          pV# V\         P                  8X  d   V P                  R,          pV# V\         P                  8X  d   V P                  R,          pV# V\         P
                  8X  d   V P                  R,          pV# V\         P                  8X  d   V P                  R,          pV# \        RV R24      h)zsGet the [x y] position of a given facial keypoint.

Args:
    keypoint: the keypoint type to return the position.

zNot valid keypoint type. Got: r-   ).)é   é   ).)é   é   ).)é   é	   ).)é
   é   ).)é   é   )r   r   r1   r   r   r   r   r0   )r2   rV   Úouts   && r   Úget_keypointÚFaceDetectorResult.get_keypointu   sÒ   € ð ”|×,Ñ,Ô,Ø—*‘*˜[Õ)ˆCð ˆ
ð œ×/Ñ/Ô/Ø—*‘*˜[Õ)ˆCð ˆ
ð œ×*Ñ*Ô*Ø—*‘*˜[Õ)ˆCð ˆ
ð œ×0Ñ0Ô0Ø—*‘*˜]Õ+ˆCð
 ˆ
ð	 œ×1Ñ1Ô1Ø—*‘*˜]Õ+ˆCð ˆ
ô Ð=¸h¸ZÀqÐIÓJÐJr   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   ‹   s   ø€ ÷ #ñ #‘u—|‘|ñ #r   c                ó(   € V P                   R,          # )zThe detection score.).é   rB   rC   s   &r   ÚscoreÚFaceDetectorResult.scoreŠ   s   € ð �z‰z˜'Õ"Ð"r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   �   s   ø€ ÷ %ñ %‘u—|‘|ñ %r   c                ó<   € V P                   V P                  ,
          # )zThe bounding box width.)rN   rD   rC   s   &r   ÚwidthÚFaceDetectorResult.width�   ó   € ð �y‰y˜4Ÿ9™9Õ$Ð$r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   •   s   ø€ ÷ %ñ %™Ÿ™ñ %r   c                ó<   € V P                   V P                  ,
          # )zThe bounding box height.)rS   rJ   rC   s   &r   ÚheightÚFaceDetectorResult.height”   rn   r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   š   s   ø€ ÷ 'ñ '™%Ÿ,™,ñ 'r   c                ó(   € V P                   R,          # )zBThe [x y] position of the top-left coordinate of the bounding box.).)rA   r,   rB   rC   s   &r   Útop_leftÚFaceDetectorResult.top_left™   ó   € ð �z‰z˜+Õ&Ð&r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   Ÿ   s   ø€ ÷ ñ ™5Ÿ<™<ñ r   c                ó\   € V P                   pVR;;,          V P                  ,          uu&   V# )zCThe [x y] position of the top-right coordinate of the bounding box.r@   )ru   rl   ©r2   rb   s   & r   Ú	top_rightÚFaceDetectorResult.top_rightž   s$   € ð �m‰mˆØˆF��t—z‘zÕ!‹Øˆ
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   ¦   s   ø€ ÷ 'ñ '™eŸl™lñ 'r   c                ó(   € V P                   R,          # )zFThe [x y] position of the bottom-right coordinate of the bounding box.).)r!   rR   rB   rC   s   &r   Úbottom_rightÚFaceDetectorResult.bottom_right¥   rw   r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r=   r$   )r'   r(   s   "€r   r)   r*   «   s   ø€ ÷ ñ ™UŸ\™\ñ r   c                ó\   € V P                   pVR;;,          V P                  ,          uu&   V# )zEThe [x y] position of the bottom-left coordinate of the bounding box.rI   )ru   rq   rz   s   & r   Úbottom_leftÚFaceDetectorResult.bottom_leftª   s$   € ð �m‰mˆØˆF��t—{‘{Õ"‹Øˆ
r   rB   )NN)r   r   r   r   r   r3   r:   ÚpropertyrD   rJ   rN   rS   rc   rh   rl   rq   ru   r{   r   rƒ   r   Ú__classdictcell__)r(   s   @r   r   r   A   s  ø‡ € ñ÷*ð ÷
ò ð
 ÷"ó ð"ð ÷"ó ð"ð ÷"ó ð"ð ÷"ó ð"÷ð ð* ÷#ó ð#ð ÷%ó ð%ð ÷%ó ð%ð ÷'ó ð'ð ÷ó ðð ÷'ó ð'ð ÷ó ör   c                   ó|   a a€ ] tR t^²t oRtRV3R lV 3R llltV3R lR ltV3R lR ltV3R lR	 ltR
t	Vt
V ;t# )r   aâ  Detect faces and five facial landmarks in RGB images in [0, 255] with the pretrained YuNet network.

``detect = FaceDetector()`` downloads the pretrained YuNet weights on first use. ``dets = detect(images)`` takes
floating-point RGB images ``(B, 3, H, W)`` in :math:`[0, 255]`, ``H`` and ``W`` at least 63. It returns a list of
``B`` tensors ``(N, 15)``, one row per face in the input's pixels, to read with :class:`FaceDetectorResult`.
Scale a :math:`[0, 1]` image by 255 first. See :cite:`facedetect-yu`.

Convention:
    - The score is ``sqrt(class_score * iou_score.clamp(0, 1))``. The detections scoring strictly above
      ``confidence_threshold`` are kept, the ``top_k`` best of them go through non-maximum suppression at the IoU
      ``nms_threshold``, and the ``keep_top_k`` best survivors are returned, highest score first.
    - Boxes and landmarks are not clipped: they can extend past the image border.

Args:
    top_k: the maximum number of detections to return before the nms.
    confidence_threshold: the threshold used to discard detections.
    nms_threshold: the threshold used by the nms for iou.
    keep_top_k: the maximum number of detections to return after the nms.

See Also:
    - :class:`FaceDetectorResult`: named access to the box, landmarks and score of the rows.
    - :class:`FaceKeypoint`: the names and order of the five landmarks.

Example:
    >>> img = torch.rand(1, 3, 320, 320) * 255  # RGB in [0, 255]
    >>> detect = FaceDetector()
    >>> res = detect(img)

c          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[ RR/# )r!   Útop_kÚconfidence_thresholdÚnms_thresholdÚ
keep_top_kr#   N)ÚintÚfloat)r'   r(   s   "€r   r)   ÚFaceDetector.__annotate__Ñ   s5   ø€ ÷ ñ ÙðÙ7<ðÙSXðÙloðà	ñr   c           
     ó(  <€ \         SV `  4        Wn        W n        W0n        W@n        R RR. RO^ ^0.^@^`.. RO.R. RORRR.RR/V n        . RO^ ^0.^@^`.. RO.V n        . ROV n        RR.V n	        RV n
        \        R	R
R7      V n        \        V n        R# )Únamer
   Ú	min_sizesÚstepsÚvariancegš™™™™™¹?gš™™™™™É?ÚclipFÚtestT)Ú
pretrainedN)r^   é   é   )é€   éÀ   é   )r\   r˜   é    é@   )Úsuperr3   r‰   rŠ   r‹   rŒ   Úconfigr’   r“   r”   r•   r
   ÚmodelÚ
nms_korniar	   )r2   r‰   rŠ   r‹   rŒ   Ú	__class__s   &&&&&€r   r3   ÚFaceDetector.__init__Ñ   s¥   ø€ ô 	‰ÑÔØŒ
Ø$8Ô!Ø*ÔØ$Œà�GØš,¨¨R¨°2°r°(ºOÐLØ’_Ø˜˜c˜
Ø�Eð
ˆŒò '¨¨R¨°2°r°(ºOÐLˆŒÚ$ˆŒ
Ø˜c˜
ˆŒØˆŒ	Ü˜6¨dÔ3ˆŒ
ÜˆŽr   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r!   Úimager#   r$   )r'   r(   s   "€r   r)   r�   ç   s#   ø€ ÷ !ñ !¡§¡ð !±·±ñ !r   c                ó   € \        V4      # )aê  Preprocess input images before feeding them to YuNet.

Args:
    image: Batch of RGB images with pixel values in :math:`[0, 255]` and shape ``(B, 3, H, W)``, where:
        - ``B`` is batch size,
        - ``3`` is the RGB channel dimension,
        - ``H`` is image height,
        - ``W`` is image width.

Returns:
    The same images in BGR channel order, still in :math:`[0, 255]`: the input YuNet was trained on.

Raises:
    ValueError: If the image is not of shape ``(*, 3, H, W)``.
r   )r2   r§   s   &&r   Ú
preprocessÚFaceDetector.preprocessç   s   € ô  ˜%Ó Ð r   c          	      ó€   <€ V ^8„  d   QhRS[ S[S[P                  3,          RS[RS[RS[S[P                  ,          /# )r!   r"   rq   rl   r#   )r   Ústrr%   r&   r�   r   )r'   r(   s   "€r   r)   r�   ù   sD   ø€ ÷ 7ñ 7¡¡S©%¯,©,Ð%6Õ 7ð 7Áð 7ÉSð 7ÑUYÑZ_×ZfÑZfÕUgñ 7r   c                ó  € VR,          VR,          VR,          rep\         P                  ! W2W2W2W2W2W2W2.VP                  VP                  R7      p\	        V P
                  V P                  V P                  W#3R7      pVP                  VP                  VP                  4      p. p	\        VP                  ^ ,          4       EF9  p
\        WJ,          V! 4       V P                  4      pW·,          pWZR^3,          WjR^ 3,          rÜWÍP                  RR4      ,          P                  4       pWàP                  8„  pW¿,          Wï,          rëVP!                  R	R
7      ^,          RV P"                   pVV,          VV,          rë\         P$                  ! W¾R,          3RR7      pV P'                  VR,          WàP(                  4      p\+        V4      ^ 8”  d   VVR3,          pV	P-                  VRV P.                   4       EK<  	  V	# )as  Decode model outputs into filtered face detections.

Args:
    data: Raw output dictionary from YuNet containing ``loc``, ``conf``,
        and ``iou`` tensors.
    height: Input image height used to scale decoded box coordinates.
    width: Input image width used to scale decoded box coordinates.

Returns:
    A list with one tensor per batch element. Each tensor is shaped
    ``(N, 15)``, where ``N`` is the number of detections kept after
    confidence filtering and non-maximum suppression (NMS).

    The 15 values per detection are:
    - 14 geometry values (bounding box + five keypoints),
    - 1 confidence score.
ÚlocÚconfÚiour9   )Ú
image_sizeºNNNg        g      ð?T)Ú
descendingN)Údim)r²   Nr.   )r²   :NrX   N)r%   Útensorr6   r7   r   r’   r“   r•   r:   Úranger/   Ú_decoder”   ÚclampÚsqrtrŠ   Úsortr‰   Úcatr	   r‹   ÚlenÚappendrŒ   )r2   r"   rq   rl   r®   r¯   r°   ÚscaleÚpriorsÚbatched_detsÚ
batch_elemÚboxesÚ
cls_scoresÚ
iou_scoresÚscoresÚindsÚorderÚdetsÚkeeps   &&&&               r   ÚpostprocessÚFaceDetector.postprocessù   s³  € ð$ ˜e� d¨6¥l°D¸µK�3ˆä—’Ø˜E¨5¸%ÈÐX]ÐglÐuØ—:‘:Ø—)‘)ô
ˆô ˜$Ÿ.™.¨$¯*©*°d·i±iÈVÈOÔ\ˆØ—‘˜3Ÿ:™: s§y¡yÓ1ˆà+-ˆÜ §	¡	¨!¥×-ˆJÜ˜C�O©V«X°t·}±}ÓEˆEØ•MˆEð &*°a¸Ð*:Õ%;¸SÈQÐPQÐAQÕ=R˜
Ø ×#3Ñ#3°C¸Ó#=Õ=×CÑCÓEˆFð ×5Ñ5Ñ5ˆDØ!�K¨­�6ð —K‘K¨4�KÓ0°Õ3°L°d·j±jÐAˆEØ! %�L¨&°­-�6ô —9’9˜e¨G¥_Ð5¸2Ô>ˆDØ—8‘8˜E %�L¨&×2DÑ2DÓEˆDÜ�4‹y˜1Œ}Ø˜D !˜G•}�ð ×Ñ Ð%6 t§¡Ð 7×8ñ1 .ð2 Ðr   c                ó^   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          /# r¦   )r%   r&   r   )r'   r(   s   "€r   r)   r�   2  s,   ø€ ÷ Cñ C™UŸ\™\ð C©d±5·<±<Õ.@ñ Cr   c                ó®   € V P                  V4      pV P                  V4      pV P                  W2P                  R,          VP                  R,          4      # )zßDetect faces in a given batch of images.

Args:
    image: batch of RGB images with pixel values in :math:`[0, 255]` and shape ``(B,3,H,W)``.

Return:
    A list of ``B`` tensors ``(N, 15)``, the detections of each image.

éþÿÿÿr.   )r©   r¡   rÊ   r/   )r2   r§   Úimgrb   s   &&  r   ÚforwardÚFaceDetector.forward2  sB   € ð �o‰o˜eÓ$ˆØ�j‰j˜‹oˆØ×Ñ §Y¡Y¨r¥]°C·I±I¸bµMÓBÐBr   )r•   rŠ   r    rŒ   r’   r¡   r	   r‹   r“   r‰   r”   )iˆ  ç333333Ó?rÒ   iî  )r   r   r   r   r   r3   r©   rÊ   rÐ   r   r†   Ú__classcell__)r£   r(   s   @@r   r   r   ²   s;   ù‡ € ñ÷<õ ÷,!ð !÷$7ð 7÷rC÷ Cð Cr   )r   r   r   )r   Úenumr   Útypingr   r   r   r%   r   Úkornia.color.rgbr   Úkornia.geometry.bboxr	   r¢   Úkornia.models.yunetr
   Úkornia.models.yunet.processorsr   r   r·   Ú__all__r   r   ÚModuler   r   r   r   Ú<module>rÜ      s\   ðñ$
õ ß 'Ñ 'ã Ý å 'Ý 2Ý %Ý 3Ý <â
@€ô�4ô ÷(nñ nôbLC�2—9‘9ö LCr   