
    >|h	                         d dl Z d dl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  ed      Z G d d	e      Z	 dd
efdZ G d d      Zy)    N)AnyList)folder_utils)Logger)FacialRecognitionzbasemodels.SFace)modulec                   @    e Zd ZdZd Zdej                  dee   fdZ	y)SFaceClientz
    SFace model class
    c                 L    t               | _        d| _        d| _        d| _        y )NSFace)p   r      )
load_modelmodel
model_nameinput_shapeoutput_shape)selfs    X/var/www/html/test/engine/venv/lib/python3.12/site-packages/deepface/basemodels/SFace.py__init__zSFaceClient.__init__   s"    \
!%    imgreturnc                     |d   dz  j                  t        j                        }| j                  j                  j	                  |      }|d   j                         S )z
        find embeddings with SFace model - different than regular models
        Args:
            img (np.ndarray): pre-loaded image in BGR
        Returns
            embeddings (list): multi-dimensional vector
        r      )astypenpuint8r   featuretolist)r   r   
input_blob
embeddingss       r   find_embeddingszSFaceClient.find_embeddings   sM     !fsl**2884
ZZ%%--j9
!}##%%r   N)
__name__
__module____qualname____doc__r   r   ndarrayr   floatr#    r   r   r
   r
      s'     &2:: &$u+ &r   r
   r   c                     t        j                         }|dz   }t        j                  j	                  |      s-t
        j                  d       t        j                  | |d       t        |      }|S )z>
    Construct SFace model, download its weights and load
    z6/.deepface/weights/face_recognition_sface_2021dec.onnxz#sface weights will be downloaded...F)quiet)
model_path)
r   get_deepface_homeospathisfileloggerinfogdowndownloadSFaceWrapper)urlhome	file_namer   s       r   r   r   .   sY     ))+DOOI77>>)$9:sIU3I.ELr   c                       e Zd Zd Zy)r6   c                     	 t         j                  j                  |ddd      | _        y# t        $ r}t        d      |d}~ww xY w)zT
        SFace wrapper covering model construction, layer infos and predict
         r   )r   config
backend_id	target_idzException while calling opencv.FaceRecognizerSF module.This is an optional dependency.You can install it as pip install opencv-contrib-python.N)cvFaceRecognizerSFcreater   	Exception
ValueError)r   r-   errs      r   r   zSFaceWrapper.__init__E   sW    		,,33 Q 4 DJ  	M 		s   (+ 	AA  AN)r$   r%   r&   r   r*   r   r   r6   r6   D   s    r   r6   )zohttps://github.com/opencv/opencv_zoo/raw/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx)r/   typingr   r   numpyr   cv2r@   r4   deepface.commonsr   deepface.commons.loggerr   !deepface.models.FacialRecognitionr   r2   r
   r   r6   r*   r   r   <module>rL      sR    	     ) * ?	)	*
&# &< 	z, r   