code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def find_image_hash(file_path: str) -> str: """ Find the hash of given image file with its properties finding the hash of image content is costly operation Args: file_path (str): exact image path Returns: hash (str): digest with sha1 algorithm """ file_stats = os.stat(fil...
Find the hash of given image file with its properties finding the hash of image content is costly operation Args: file_path (str): exact image path Returns: hash (str): digest with sha1 algorithm
find_image_hash
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def load_image(img: Union[str, np.ndarray, IO[bytes]]) -> Tuple[np.ndarray, str]: """ Load image from path, url, file object, base64 or numpy array. Args: img: a path, url, file object, base64 or numpy array. Returns: image (numpy array): the loaded image in BGR format image name...
Load image from path, url, file object, base64 or numpy array. Args: img: a path, url, file object, base64 or numpy array. Returns: image (numpy array): the loaded image in BGR format image name (str): image name itself
load_image
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def load_image_from_io_object(obj: IO[bytes]) -> np.ndarray: """ Load image from an object that supports being read Args: obj: a file like object. Returns: img (np.ndarray): The decoded image as a numpy array (OpenCV format). """ try: _ = obj.seek(0) except (Attribute...
Load image from an object that supports being read Args: obj: a file like object. Returns: img (np.ndarray): The decoded image as a numpy array (OpenCV format).
load_image_from_io_object
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def load_image_from_base64(uri: str) -> np.ndarray: """ Load image from base64 string. Args: uri: a base64 string. Returns: numpy array: the loaded image. """ encoded_data_parts = uri.split(",") if len(encoded_data_parts) < 2: raise ValueError("format error in base6...
Load image from base64 string. Args: uri: a base64 string. Returns: numpy array: the loaded image.
load_image_from_base64
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def load_image_from_file_storage(file: FileStorage) -> np.ndarray: """ Loads an image from a FileStorage object and decodes it into an OpenCV image. Args: file (FileStorage): The FileStorage object containing the image file. Returns: img (np.ndarray): The decoded image as a numpy array (...
Loads an image from a FileStorage object and decodes it into an OpenCV image. Args: file (FileStorage): The FileStorage object containing the image file. Returns: img (np.ndarray): The decoded image as a numpy array (OpenCV format).
load_image_from_file_storage
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def load_image_from_web(url: str) -> np.ndarray: """ Loading an image from web Args: url: link for the image Returns: img (np.ndarray): equivalent to pre-loaded image from opencv (BGR format) """ response = requests.get(url, stream=True, timeout=60) response.raise_for_status(...
Loading an image from web Args: url: link for the image Returns: img (np.ndarray): equivalent to pre-loaded image from opencv (BGR format)
load_image_from_web
python
serengil/deepface
deepface/commons/image_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/image_utils.py
MIT
def find_file_hash(file_path: str, hash_algorithm: str = "sha256") -> str: """ Find the hash of a given file with its content Args: file_path (str): exact path of a given file hash_algorithm (str): hash algorithm Returns: hash (str) """ hash_func = hashlib.new(hash_algori...
Find the hash of a given file with its content Args: file_path (str): exact path of a given file hash_algorithm (str): hash algorithm Returns: hash (str)
find_file_hash
python
serengil/deepface
deepface/commons/package_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/package_utils.py
MIT
def load_model_weights(model: Sequential, weight_file: str) -> Sequential: """ Load pre-trained weights for a given model Args: model (keras.models.Sequential): pre-built model weight_file (str): exact path of pre-trained weights Returns: model (keras.models.Sequential): pre-buil...
Load pre-trained weights for a given model Args: model (keras.models.Sequential): pre-built model weight_file (str): exact path of pre-trained weights Returns: model (keras.models.Sequential): pre-built model with updated weights
load_model_weights
python
serengil/deepface
deepface/commons/weight_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/weight_utils.py
MIT
def download_all_models_in_one_shot() -> None: """ Download all model weights in one shot """ # import model weights from module here to avoid circular import issue from deepface.models.facial_recognition.VGGFace import WEIGHTS_URL as VGGFACE_WEIGHTS from deepface.models.facial_recognition.Face...
Download all model weights in one shot
download_all_models_in_one_shot
python
serengil/deepface
deepface/commons/weight_utils.py
https://github.com/serengil/deepface/blob/master/deepface/commons/weight_utils.py
MIT
def _predict_internal(self, img_batch: np.ndarray) -> np.ndarray: """ Predict for single image or batched images. This method uses legacy method while receiving single image as input. And switch to batch prediction if receives batched images. Args: img_batch: ...
Predict for single image or batched images. This method uses legacy method while receiving single image as input. And switch to batch prediction if receives batched images. Args: img_batch: Batch of images as np.ndarray (n, x, y, c) with ...
_predict_internal
python
serengil/deepface
deepface/models/Demography.py
https://github.com/serengil/deepface/blob/master/deepface/models/Demography.py
MIT
def _preprocess_batch_or_single_input( self, img: Union[np.ndarray, List[np.ndarray]] ) -> np.ndarray: """ Preprocess single or batch of images, return as 4-D numpy array. Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.nd...
Preprocess single or batch of images, return as 4-D numpy array. Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.ndarray (n, 224, 224, 3) Returns: Four-dimensional numpy ...
_preprocess_batch_or_single_input
python
serengil/deepface
deepface/models/Demography.py
https://github.com/serengil/deepface/blob/master/deepface/models/Demography.py
MIT
def predict(self, img: Union[np.ndarray, List[np.ndarray]]) -> Union[np.float64, np.ndarray]: """ Predict apparent age(s) for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of...
Predict apparent age(s) for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.ndarray (n, 224, 224, 3) Returns: np.ndarray (age_classes,) if single i...
predict
python
serengil/deepface
deepface/models/demography/Age.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Age.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct age model, download its weights and load Returns: model (Model) """ model = VGGFace.base_model() # -------------------------- classes = 101 base_model_output = Sequential() base_model_output = Convolution2D(cla...
Construct age model, download its weights and load Returns: model (Model)
load_model
python
serengil/deepface
deepface/models/demography/Age.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Age.py
MIT
def find_apparent_age(age_predictions: np.ndarray) -> np.float64: """ Find apparent age prediction from a given probas of ages Args: age_predictions (age_classes,) Returns: apparent_age (float) """ assert ( len(age_predictions.shape) == 1 ), f"Input should be a list o...
Find apparent age prediction from a given probas of ages Args: age_predictions (age_classes,) Returns: apparent_age (float)
find_apparent_age
python
serengil/deepface
deepface/models/demography/Age.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Age.py
MIT
def _preprocess_image(self, img: np.ndarray) -> np.ndarray: """ Preprocess single image for emotion detection Args: img: Input image (224, 224, 3) Returns: Preprocessed grayscale image (48, 48) """ img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ...
Preprocess single image for emotion detection Args: img: Input image (224, 224, 3) Returns: Preprocessed grayscale image (48, 48)
_preprocess_image
python
serengil/deepface
deepface/models/demography/Emotion.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Emotion.py
MIT
def predict(self, img: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray: """ Predict emotion probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np...
Predict emotion probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.ndarray (n, 224, 224, 3) Returns: np.ndarray (n, n_emotions) ...
predict
python
serengil/deepface
deepface/models/demography/Emotion.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Emotion.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Sequential: """ Consruct emotion model, download and load weights """ num_classes = 7 model = Sequential() # 1st convolution layer model.add(Conv2D(64, (5, 5), activation="relu", input_shape=(48, 48, 1))) model.add(MaxPooling2D(pool_size=(5, 5...
Consruct emotion model, download and load weights
load_model
python
serengil/deepface
deepface/models/demography/Emotion.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Emotion.py
MIT
def predict(self, img: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray: """ Predict gender probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np....
Predict gender probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.ndarray (n, 224, 224, 3) Returns: np.ndarray (n, 2)
predict
python
serengil/deepface
deepface/models/demography/Gender.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Gender.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct gender model, download its weights and load Returns: model (Model) """ model = VGGFace.base_model() # -------------------------- classes = 2 base_model_output = Sequential() base_model_output = Convolution2D(cl...
Construct gender model, download its weights and load Returns: model (Model)
load_model
python
serengil/deepface
deepface/models/demography/Gender.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Gender.py
MIT
def predict(self, img: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray: """ Predict race probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.nd...
Predict race probabilities for single or multiple faces Args: img: Single image as np.ndarray (224, 224, 3) or List of images as List[np.ndarray] or Batch of images as np.ndarray (n, 224, 224, 3) Returns: np.ndarray (n, n_races) ...
predict
python
serengil/deepface
deepface/models/demography/Race.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Race.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct race model, download its weights and load """ model = VGGFace.base_model() # -------------------------- classes = 6 base_model_output = Sequential() base_model_output = Convolution2D(classes, (1, 1), name="predictions")(mo...
Construct race model, download its weights and load
load_model
python
serengil/deepface
deepface/models/demography/Race.py
https://github.com/serengil/deepface/blob/master/deepface/models/demography/Race.py
MIT
def build_model(self): """ Download pre-trained weights of CenterFace model if necessary and load built model """ weights_path = weight_utils.download_weights_if_necessary( file_name="centerface.onnx", source_url=WEIGHTS_URL ) return CenterFace(weight_path=we...
Download pre-trained weights of CenterFace model if necessary and load built model
build_model
python
serengil/deepface
deepface/models/face_detection/CenterFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/CenterFace.py
MIT
def detect_faces(self, img: np.ndarray) -> List["FacialAreaRegion"]: """ Detect and align face with CenterFace Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ ...
Detect and align face with CenterFace Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/CenterFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/CenterFace.py
MIT
def build_model(self) -> dict: """ Build a dlib hog face detector model Returns: model (Any) """ # this is not a must dependency. do not import it in the global level. try: import dlib except ModuleNotFoundError as e: raise Impo...
Build a dlib hog face detector model Returns: model (Any)
build_model
python
serengil/deepface
deepface/models/face_detection/Dlib.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Dlib.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with dlib Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ resp ...
Detect and align face with dlib Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/Dlib.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Dlib.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with mtcnn Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ resp...
Detect and align face with mtcnn Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/FastMtCnn.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/FastMtCnn.py
MIT
def build_model(self) -> Any: """ Build a fast mtcnn face detector model Returns: model (Any) """ # this is not a must dependency. do not import it in the global level. try: from facenet_pytorch import MTCNN as fast_mtcnn import torch ...
Build a fast mtcnn face detector model Returns: model (Any)
build_model
python
serengil/deepface
deepface/models/face_detection/FastMtCnn.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/FastMtCnn.py
MIT
def xyxy_to_xywh(regions: Union[list, tuple]) -> tuple: """ Convert (x1, y1, x2, y2) format to (x, y, w, h) format. Args: regions (list or tuple): facial area coordinates as x, y, x+w, y+h Returns: regions (tuple): facial area coordinates as x, y, w, h """ x, y, x_plus_w, y_plus_...
Convert (x1, y1, x2, y2) format to (x, y, w, h) format. Args: regions (list or tuple): facial area coordinates as x, y, x+w, y+h Returns: regions (tuple): facial area coordinates as x, y, w, h
xyxy_to_xywh
python
serengil/deepface
deepface/models/face_detection/FastMtCnn.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/FastMtCnn.py
MIT
def build_model(self) -> Any: """ Build a mediapipe face detector model Returns: model (Any) """ # this is not a must dependency. do not import it in the global level. try: import mediapipe as mp except ModuleNotFoundError as e: ...
Build a mediapipe face detector model Returns: model (Any)
build_model
python
serengil/deepface
deepface/models/face_detection/MediaPipe.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/MediaPipe.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with mediapipe Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ ...
Detect and align face with mediapipe Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/MediaPipe.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/MediaPipe.py
MIT
def build_model(self): """ Build opencv's face and eye detector models Returns: model (dict): including face_detector and eye_detector keys """ detector = {} detector["face_detector"] = self.__build_cascade("haarcascade") detector["eye_detector"] = sel...
Build opencv's face and eye detector models Returns: model (dict): including face_detector and eye_detector keys
build_model
python
serengil/deepface
deepface/models/face_detection/OpenCv.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/OpenCv.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with opencv Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ res...
Detect and align face with opencv Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/OpenCv.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/OpenCv.py
MIT
def find_eyes(self, img: np.ndarray) -> tuple: """ Find the left and right eye coordinates of given image Args: img (np.ndarray): given image Returns: left and right eye (tuple) """ left_eye = None right_eye = None # if image has u...
Find the left and right eye coordinates of given image Args: img (np.ndarray): given image Returns: left and right eye (tuple)
find_eyes
python
serengil/deepface
deepface/models/face_detection/OpenCv.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/OpenCv.py
MIT
def __build_cascade(self, model_name="haarcascade") -> Any: """ Build a opencv face&eye detector models Returns: model (Any) """ opencv_path = self.__get_opencv_path() if model_name == "haarcascade": face_detector_path = os.path.join(opencv_path, "...
Build a opencv face&eye detector models Returns: model (Any)
__build_cascade
python
serengil/deepface
deepface/models/face_detection/OpenCv.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/OpenCv.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with retinaface Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ ...
Detect and align face with retinaface Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/RetinaFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/RetinaFace.py
MIT
def build_model(self) -> dict: """ Build a ssd detector model Returns: model (dict) """ # model structure output_model = weight_utils.download_weights_if_necessary( file_name="deploy.prototxt", source_url=MODEL_URL, ) ...
Build a ssd detector model Returns: model (dict)
build_model
python
serengil/deepface
deepface/models/face_detection/Ssd.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Ssd.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with ssd Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ # Bec...
Detect and align face with ssd Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/Ssd.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Ssd.py
MIT
def build_model(self, model: YoloModel) -> Any: """ Build a yolo detector model Returns: model (Any) """ # Import the optional Ultralytics YOLO model try: from ultralytics import YOLO except ModuleNotFoundError as e: raise Impo...
Build a yolo detector model Returns: model (Any)
build_model
python
serengil/deepface
deepface/models/face_detection/Yolo.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Yolo.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with yolo Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ resp ...
Detect and align face with yolo Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/Yolo.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/Yolo.py
MIT
def build_model(self) -> Any: """ Build a yunet detector model Returns: model (Any) """ opencv_version = cv2.__version__.split(".") if not len(opencv_version) >= 2: raise ValueError( f"OpenCv's version must have major and minor val...
Build a yunet detector model Returns: model (Any)
build_model
python
serengil/deepface
deepface/models/face_detection/YuNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/YuNet.py
MIT
def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]: """ Detect and align face with yunet Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects """ # Fa...
Detect and align face with yunet Args: img (np.ndarray): pre-loaded image as numpy array Returns: results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
detect_faces
python
serengil/deepface
deepface/models/face_detection/YuNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/face_detection/YuNet.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct ArcFace model, download its weights and load Returns: model (Model) """ base_model = ResNet34() inputs = base_model.inputs[0] arcface_model = base_model.outputs[0] arcface_model = BatchNormalization(momentum=0.9, epsi...
Construct ArcFace model, download its weights and load Returns: model (Model)
load_model
python
serengil/deepface
deepface/models/facial_recognition/ArcFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/ArcFace.py
MIT
def preprocess(self, img: np.ndarray) -> np.ndarray: """ Preprocess the input image or batch of images. Args: img: Input image or batch with shape (112, 112, 3) or (batch_size, 112, 112, 3). Returns: Preprocessed image(s) with RGB converted to BGR. ...
Preprocess the input image or batch of images. Args: img: Input image or batch with shape (112, 112, 3) or (batch_size, 112, 112, 3). Returns: Preprocessed image(s) with RGB converted to BGR.
preprocess
python
serengil/deepface
deepface/models/facial_recognition/Buffalo_L.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Buffalo_L.py
MIT
def forward(self, img: np.ndarray) -> Union[List[float], List[List[float]]]: """ Extract facial embedding(s) from the input image or batch of images. Args: img: Input image or batch with shape (112, 112, 3) or (batch_size, 112, 112, 3). Returns: Emb...
Extract facial embedding(s) from the input image or batch of images. Args: img: Input image or batch with shape (112, 112, 3) or (batch_size, 112, 112, 3). Returns: Embedding as a list of floats (single image) or list of lists of floats (batch...
forward
python
serengil/deepface
deepface/models/facial_recognition/Buffalo_L.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Buffalo_L.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct DeepId model, download its weights and load """ myInput = Input(shape=(55, 47, 3)) x = Conv2D(20, (4, 4), name="Conv1", activation="relu", input_shape=(55, 47, 3))(myInput) x = MaxPooling2D(pool_size=2, strides=2, name="Pool1")(x) ...
Construct DeepId model, download its weights and load
load_model
python
serengil/deepface
deepface/models/facial_recognition/DeepID.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/DeepID.py
MIT
def forward(self, img: np.ndarray) -> Union[List[float], List[List[float]]]: """ Find embeddings with Dlib model. This model necessitates the override of the forward method because it is not a keras model. Args: img (np.ndarray): pre-loaded image(s) in BGR ...
Find embeddings with Dlib model. This model necessitates the override of the forward method because it is not a keras model. Args: img (np.ndarray): pre-loaded image(s) in BGR Returns embeddings (list of lists or list of floats): multi-dimensional...
forward
python
serengil/deepface
deepface/models/facial_recognition/Dlib.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Dlib.py
MIT
def InceptionResNetV1(dimension: int = 128) -> Model: """ InceptionResNetV1 model heavily inspired from github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py As mentioned in Sandberg's repo's readme, pre-trained models are using Inception ResNet v1 Besides training process i...
InceptionResNetV1 model heavily inspired from github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py As mentioned in Sandberg's repo's readme, pre-trained models are using Inception ResNet v1 Besides training process is documented at sefiks.com/2018/09/03/face-recognition-wi...
InceptionResNetV1
python
serengil/deepface
deepface/models/facial_recognition/Facenet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Facenet.py
MIT
def load_facenet128d_model( url=FACENET128_WEIGHTS, ) -> Model: """ Construct FaceNet-128d model, download weights and then load weights Args: dimension (int): construct FaceNet-128d or FaceNet-512d models Returns: model (Model) """ model = InceptionResNetV1() weight_fil...
Construct FaceNet-128d model, download weights and then load weights Args: dimension (int): construct FaceNet-128d or FaceNet-512d models Returns: model (Model)
load_facenet128d_model
python
serengil/deepface
deepface/models/facial_recognition/Facenet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Facenet.py
MIT
def load_facenet512d_model( url=FACENET512_WEIGHTS, ) -> Model: """ Construct FaceNet-512d model, download its weights and load Returns: model (Model) """ model = InceptionResNetV1(dimension=512) weight_file = weight_utils.download_weights_if_necessary( file_name="facenet51...
Construct FaceNet-512d model, download its weights and load Returns: model (Model)
load_facenet512d_model
python
serengil/deepface
deepface/models/facial_recognition/Facenet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/Facenet.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Construct DeepFace model, download its weights and load """ # we have some checks for this dependency in the init of client # putting this in global causes library initialization if tf_major == 1: from keras.layers import LocallyConnec...
Construct DeepFace model, download its weights and load
load_model
python
serengil/deepface
deepface/models/facial_recognition/FbDeepFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/FbDeepFace.py
MIT
def GhostFaceNetV1() -> Model: """ Build GhostFaceNetV1 model. Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py Returns: model (Model) """ inputs = Input(shape=(112, 112, 3)) out_channel = 20 nn = Conv2D( out_channel, (3, 3...
Build GhostFaceNetV1 model. Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py Returns: model (Model)
GhostFaceNetV1
python
serengil/deepface
deepface/models/facial_recognition/GhostFaceNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/GhostFaceNet.py
MIT
def se_module(inputs, reduction): """ Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py """ # get the channel axis channel_axis = 1 if K.image_data_format() == "channels_first" else -1 # filters = channel axis shape filters = inputs.shape[channel_axis] ...
Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py
se_module
python
serengil/deepface
deepface/models/facial_recognition/GhostFaceNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/GhostFaceNet.py
MIT
def replace_relu_with_prelu(model) -> Model: """ Replaces relu activation function in the built model with prelu. Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py Args: model (Model): built model with relu activation functions Returns model (Mod...
Replaces relu activation function in the built model with prelu. Refactored from github.com/HamadYA/GhostFaceNets/blob/main/backbones/ghost_model.py Args: model (Model): built model with relu activation functions Returns model (Model): built model with prelu activation functions ...
replace_relu_with_prelu
python
serengil/deepface
deepface/models/facial_recognition/GhostFaceNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/GhostFaceNet.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Consturct OpenFace model, download its weights and load Returns: model (Model) """ myInput = Input(shape=(96, 96, 3)) x = ZeroPadding2D(padding=(3, 3), input_shape=(96, 96, 3))(myInput) x = Conv2D(64, (7, 7), strides=(2, 2), name=...
Consturct OpenFace model, download its weights and load Returns: model (Model)
load_model
python
serengil/deepface
deepface/models/facial_recognition/OpenFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/OpenFace.py
MIT
def forward(self, img: np.ndarray) -> Union[List[float], List[List[float]]]: """ Find embeddings with SFace model This model necessitates the override of the forward method because it is not a keras model. Args: img (np.ndarray): pre-loaded image in BGR ...
Find embeddings with SFace model This model necessitates the override of the forward method because it is not a keras model. Args: img (np.ndarray): pre-loaded image in BGR Returns embeddings (list): multi-dimensional vector
forward
python
serengil/deepface
deepface/models/facial_recognition/SFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/SFace.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Any: """ Construct SFace model, download its weights and load """ weight_file = weight_utils.download_weights_if_necessary( file_name="face_recognition_sface_2021dec.onnx", source_url=url ) model = SFaceWrapper(model_path=weight_file) retu...
Construct SFace model, download its weights and load
load_model
python
serengil/deepface
deepface/models/facial_recognition/SFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/SFace.py
MIT
def __init__(self, model_path): """ SFace wrapper covering model construction, layer infos and predict """ try: self.model = cv.FaceRecognizerSF.create( model=model_path, config="", backend_id=0, target_id=0 ) except Exception as err: ...
SFace wrapper covering model construction, layer infos and predict
__init__
python
serengil/deepface
deepface/models/facial_recognition/SFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/SFace.py
MIT
def forward(self, img: np.ndarray) -> List[float]: """ Generates embeddings using the VGG-Face model. This method incorporates an additional normalization layer. Args: img (np.ndarray): pre-loaded image in BGR Returns embeddings (list): multi-dimensio...
Generates embeddings using the VGG-Face model. This method incorporates an additional normalization layer. Args: img (np.ndarray): pre-loaded image in BGR Returns embeddings (list): multi-dimensional vector
forward
python
serengil/deepface
deepface/models/facial_recognition/VGGFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/VGGFace.py
MIT
def base_model() -> Sequential: """ Base model of VGG-Face being used for classification - not to find embeddings Returns: model (Sequential): model was trained to classify 2622 identities """ model = Sequential() model.add(ZeroPadding2D((1, 1), input_shape=(224, 224, 3))) model.add(...
Base model of VGG-Face being used for classification - not to find embeddings Returns: model (Sequential): model was trained to classify 2622 identities
base_model
python
serengil/deepface
deepface/models/facial_recognition/VGGFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/VGGFace.py
MIT
def load_model( url=WEIGHTS_URL, ) -> Model: """ Final VGG-Face model being used for finding embeddings Returns: model (Model): returning 4096 dimensional vectors """ model = base_model() weight_file = weight_utils.download_weights_if_necessary( file_name="vgg_face_weights....
Final VGG-Face model being used for finding embeddings Returns: model (Model): returning 4096 dimensional vectors
load_model
python
serengil/deepface
deepface/models/facial_recognition/VGGFace.py
https://github.com/serengil/deepface/blob/master/deepface/models/facial_recognition/VGGFace.py
MIT
def analyze(self, img: np.ndarray, facial_area: Union[list, tuple]): """ Analyze a given image spoofed or not Args: img (np.ndarray): pre loaded image facial_area (list or tuple): facial rectangle area coordinates with x, y, w, h respectively Returns: ...
Analyze a given image spoofed or not Args: img (np.ndarray): pre loaded image facial_area (list or tuple): facial rectangle area coordinates with x, y, w, h respectively Returns: result (tuple): a result tuple consisting of is_real and score
analyze
python
serengil/deepface
deepface/models/spoofing/FasNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/spoofing/FasNet.py
MIT
def to_tensor(pic): """Convert a ``numpy.ndarray`` to tensor. See ``ToTensor`` for more details. Args: pic (PIL Image or numpy.ndarray): Image to be converted to tensor. Returns: Tensor: Converted image. """ import torch # handle numpy array # IR image channel=1: modi...
Convert a ``numpy.ndarray`` to tensor. See ``ToTensor`` for more details. Args: pic (PIL Image or numpy.ndarray): Image to be converted to tensor. Returns: Tensor: Converted image.
to_tensor
python
serengil/deepface
deepface/models/spoofing/FasNet.py
https://github.com/serengil/deepface/blob/master/deepface/models/spoofing/FasNet.py
MIT
def analyze( img_path: Union[str, np.ndarray, IO[bytes], List[str], List[np.ndarray], List[IO[bytes]]], actions: Union[tuple, list] = ("emotion", "age", "gender", "race"), enforce_detection: bool = True, detector_backend: str = "opencv", align: bool = True, expand_percentage: int = 0, silent...
Analyze facial attributes such as age, gender, emotion, and race in the provided image. Args: img_path (str, np.ndarray, IO[bytes], list): The exact path to the image, a numpy array in BGR format, or a base64 encoded image. If the source image contains multiple faces, the resul...
analyze
python
serengil/deepface
deepface/modules/demography.py
https://github.com/serengil/deepface/blob/master/deepface/modules/demography.py
MIT
def extract_faces( img_path: Union[str, np.ndarray, IO[bytes]], detector_backend: str = "opencv", enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, grayscale: bool = False, color_face: str = "rgb", normalize_face: bool = True, anti_spoofing: bool = False...
Extract faces from a given image Args: img_path (str or np.ndarray or IO[bytes]): Path to the first image. Accepts exact image path as a string, numpy array (BGR), a file object that supports at least `.read` and is opened in binary mode, or base64 encoded images. dete...
extract_faces
python
serengil/deepface
deepface/modules/detection.py
https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py
MIT
def detect_faces( detector_backend: str, img: np.ndarray, align: bool = True, expand_percentage: int = 0, max_faces: Optional[int] = None, ) -> List[DetectedFace]: """ Detect face(s) from a given image Args: detector_backend (str): detector name img (np.ndarray): pre-loa...
Detect face(s) from a given image Args: detector_backend (str): detector name img (np.ndarray): pre-loaded image align (bool): enable or disable alignment after detection expand_percentage (int): expand detected facial area with a percentage (default is 0). Returns: ...
detect_faces
python
serengil/deepface
deepface/modules/detection.py
https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py
MIT
def extract_sub_image( img: np.ndarray, facial_area: Tuple[int, int, int, int] ) -> Tuple[np.ndarray, int, int]: """ Get the sub image with given facial area while expanding the facial region to ensure alignment does not shift the face outside the image. This function doubles the height and wid...
Get the sub image with given facial area while expanding the facial region to ensure alignment does not shift the face outside the image. This function doubles the height and width of the face region, and adds black pixels if necessary. Args: - img (np.ndarray): pre-loaded image with ...
extract_sub_image
python
serengil/deepface
deepface/modules/detection.py
https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py
MIT
def align_img_wrt_eyes( img: np.ndarray, left_eye: Optional[Union[list, tuple]], right_eye: Optional[Union[list, tuple]], ) -> Tuple[np.ndarray, float]: """ Align a given image horizantally with respect to their left and right eye locations Args: img (np.ndarray): pre-loaded image with d...
Align a given image horizantally with respect to their left and right eye locations Args: img (np.ndarray): pre-loaded image with detected face left_eye (list or tuple): coordinates of left eye with respect to the person itself right_eye(list or tuple): coordinates of right eye with res...
align_img_wrt_eyes
python
serengil/deepface
deepface/modules/detection.py
https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py
MIT
def project_facial_area( facial_area: Tuple[int, int, int, int], angle: float, size: Tuple[int, int] ) -> Tuple[int, int, int, int]: """ Update pre-calculated facial area coordinates after image itself rotated with respect to the eyes. Inspried from the work of @UmutDeniz26 - github.com/serengil...
Update pre-calculated facial area coordinates after image itself rotated with respect to the eyes. Inspried from the work of @UmutDeniz26 - github.com/serengil/retinaface/pull/80 Args: facial_area (tuple of int): Representing the (x1, y1, x2, y2) of the facial area. x2 is equal...
project_facial_area
python
serengil/deepface
deepface/modules/detection.py
https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py
MIT
def build_model(task: str, model_name: str) -> Any: """ This function loads a pre-trained models as singletonish way Parameters: task (str): facial_recognition, facial_attribute, face_detector, spoofing model_name (str): model identifier - VGG-Face, Facenet, Facenet512, OpenFace,...
This function loads a pre-trained models as singletonish way Parameters: task (str): facial_recognition, facial_attribute, face_detector, spoofing model_name (str): model identifier - VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and...
build_model
python
serengil/deepface
deepface/modules/modeling.py
https://github.com/serengil/deepface/blob/master/deepface/modules/modeling.py
MIT
def resize_image(img: np.ndarray, target_size: Tuple[int, int]) -> np.ndarray: """ Resize an image to expected size of a ml model with adding black pixels. Args: img (np.ndarray): pre-loaded image as numpy array target_size (tuple): input shape of ml model Returns: img (np.ndarra...
Resize an image to expected size of a ml model with adding black pixels. Args: img (np.ndarray): pre-loaded image as numpy array target_size (tuple): input shape of ml model Returns: img (np.ndarray): resized input image
resize_image
python
serengil/deepface
deepface/modules/preprocessing.py
https://github.com/serengil/deepface/blob/master/deepface/modules/preprocessing.py
MIT
def find( img_path: Union[str, np.ndarray], db_path: str, model_name: str = "VGG-Face", distance_metric: str = "cosine", enforce_detection: bool = True, detector_backend: str = "opencv", align: bool = True, expand_percentage: int = 0, threshold: Optional[float] = None, normalizat...
Identify individuals in a database Args: img_path (str or np.ndarray): The exact path to the image, a numpy array in BGR format, or a base64 encoded image. If the source image contains multiple faces, the result will include information for each detected face. db_path ...
find
python
serengil/deepface
deepface/modules/recognition.py
https://github.com/serengil/deepface/blob/master/deepface/modules/recognition.py
MIT
def __find_bulk_embeddings( employees: Set[str], model_name: str = "VGG-Face", detector_backend: str = "opencv", enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, normalization: str = "base", silent: bool = False, ) -> List[Dict["str", Any]]: """ Fin...
Find embeddings of a list of images Args: employees (list): list of exact image paths model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face). detector_ba...
__find_bulk_embeddings
python
serengil/deepface
deepface/modules/recognition.py
https://github.com/serengil/deepface/blob/master/deepface/modules/recognition.py
MIT
def find_batched( representations: List[Dict[str, Any]], source_objs: List[Dict[str, Any]], model_name: str = "VGG-Face", distance_metric: str = "cosine", enforce_detection: bool = True, align: bool = True, threshold: Optional[float] = None, normalization: str = "base", anti_spoofing...
Perform batched face recognition by comparing source face embeddings with a set of target embeddings. It calculates pairwise distances between the source and target embeddings using the specified distance metric. The function uses batch processing for efficient computation of distances. Args: ...
find_batched
python
serengil/deepface
deepface/modules/recognition.py
https://github.com/serengil/deepface/blob/master/deepface/modules/recognition.py
MIT
def analysis( db_path: str, model_name="VGG-Face", detector_backend="opencv", distance_metric="cosine", enable_face_analysis=True, source=0, time_threshold=5, frame_threshold=5, anti_spoofing: bool = False, output_path: Optional[str] = None, debug: bool = False, ): """ ...
Run real time face recognition and facial attribute analysis Args: db_path (string): Path to the folder containing image files. All detected faces in the database will be considered in the decision-making process. model_name (str): Model for face recognition. Options: VGG-Face, Fa...
analysis
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def build_facial_recognition_model(model_name: str) -> None: """ Build facial recognition model Args: model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face). Returns...
Build facial recognition model Args: model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face). Returns input_shape (tuple): input shape of given facial recognitio...
build_facial_recognition_model
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def search_identity( detected_face: np.ndarray, db_path: str, model_name: str, detector_backend: str, distance_metric: str, ) -> Tuple[Optional[str], Optional[np.ndarray]]: """ Search an identity in facial database. Args: detected_face (np.ndarray): extracted individual facial im...
Search an identity in facial database. Args: detected_face (np.ndarray): extracted individual facial image db_path (string): Path to the folder containing image files. All detected faces in the database will be considered in the decision-making process. model_name (str): Mod...
search_identity
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def build_demography_models(enable_face_analysis: bool) -> None: """ Build demography analysis models Args: enable_face_analysis (bool): Flag to enable face analysis (default is True). Returns: None """ if enable_face_analysis is False: return DeepFace.build_model(tas...
Build demography analysis models Args: enable_face_analysis (bool): Flag to enable face analysis (default is True). Returns: None
build_demography_models
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def highlight_facial_areas( img: np.ndarray, faces_coordinates: List[Tuple[int, int, int, int, bool, float]], anti_spoofing: bool = False, ) -> np.ndarray: """ Highlight detected faces with rectangles in the given image Args: img (np.ndarray): image itself faces_coordinates (list...
Highlight detected faces with rectangles in the given image Args: img (np.ndarray): image itself faces_coordinates (list): list of face coordinates as tuple with x, y, w and h also is_real and antispoof_score keys anti_spoofing (boolean): Flag to enable anti spoofing (defaul...
highlight_facial_areas
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def countdown_to_freeze( img: np.ndarray, faces_coordinates: List[Tuple[int, int, int, int, bool, float]], frame_threshold: int, num_frames_with_faces: int, ) -> np.ndarray: """ Highlight time to freeze in the image's facial areas Args: img (np.ndarray): image itself faces_co...
Highlight time to freeze in the image's facial areas Args: img (np.ndarray): image itself faces_coordinates (list): list of face coordinates as tuple with x, y, w and h frame_threshold (int): how many sequantial frames required with face(s) to freeze num_frames_with_faces (int):...
countdown_to_freeze
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def countdown_to_release( img: Optional[np.ndarray], tic: float, time_threshold: int ) -> Optional[np.ndarray]: """ Highlight time to release the freezing in the image top left area Args: img (np.ndarray): image itself tic (float): time specifying when freezing started time_thres...
Highlight time to release the freezing in the image top left area Args: img (np.ndarray): image itself tic (float): time specifying when freezing started time_threshold (int): freeze time threshold Returns: img (np.ndarray): image with time to release the freezing
countdown_to_release
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def grab_facial_areas( img: np.ndarray, detector_backend: str, threshold: int = 130, anti_spoofing: bool = False ) -> List[Tuple[int, int, int, int, bool, float]]: """ Find facial area coordinates in the given image Args: img (np.ndarray): image itself detector_backend (string): face det...
Find facial area coordinates in the given image Args: img (np.ndarray): image itself detector_backend (string): face detector backend. Options: 'opencv', 'retinaface', 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m', 'centerface' or 'ski...
grab_facial_areas
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def extract_facial_areas( img: np.ndarray, faces_coordinates: List[Tuple[int, int, int, int, bool, float]] ) -> List[np.ndarray]: """ Extract facial areas as numpy array from given image Args: img (np.ndarray): image itself faces_coordinates (list): list of facial area coordinates as tup...
Extract facial areas as numpy array from given image Args: img (np.ndarray): image itself faces_coordinates (list): list of facial area coordinates as tuple with x, y, w and h values also is_real and antispoof_score keys Returns: detected_faces (list): list of detected f...
extract_facial_areas
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def perform_facial_recognition( img: np.ndarray, detected_faces: List[np.ndarray], faces_coordinates: List[Tuple[int, int, int, int, bool, float]], db_path: str, detector_backend: str, distance_metric: str, model_name: str, ) -> np.ndarray: """ Perform facial recognition Args: ...
Perform facial recognition Args: img (np.ndarray): image itself detected_faces (list): list of extracted detected face images as numpy faces_coordinates (list): list of facial area coordinates as tuple with x, y, w and h values also is_real and antispoof_score keys d...
perform_facial_recognition
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def perform_demography_analysis( enable_face_analysis: bool, img: np.ndarray, faces_coordinates: List[Tuple[int, int, int, int, bool, float]], detected_faces: List[np.ndarray], ) -> np.ndarray: """ Perform demography analysis on given image Args: enable_face_analysis (bool): Flag to ...
Perform demography analysis on given image Args: enable_face_analysis (bool): Flag to enable face analysis. img (np.ndarray): image itself faces_coordinates (list): list of face coordinates as tuple with x, y, w and h values also is_real and antispoof_score keys dete...
perform_demography_analysis
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def overlay_identified_face( img: np.ndarray, target_img: np.ndarray, label: str, x: int, y: int, w: int, h: int, ) -> np.ndarray: """ Overlay the identified face onto image itself Args: img (np.ndarray): image itself target_img (np.ndarray): identified face's ima...
Overlay the identified face onto image itself Args: img (np.ndarray): image itself target_img (np.ndarray): identified face's image label (str): name of the identified face x (int): x coordinate of the face on the given image y (int): y coordinate of the face on the give...
overlay_identified_face
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def overlay_emotion( img: np.ndarray, emotion_probas: dict, x: int, y: int, w: int, h: int ) -> np.ndarray: """ Overlay the analyzed emotion of face onto image itself Args: img (np.ndarray): image itself emotion_probas (dict): probability of different emotionas dictionary x (int)...
Overlay the analyzed emotion of face onto image itself Args: img (np.ndarray): image itself emotion_probas (dict): probability of different emotionas dictionary x (int): x coordinate of the face on the given image y (int): y coordinate of the face on the given image w (i...
overlay_emotion
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def overlay_age_gender( img: np.ndarray, apparent_age: float, gender: str, x: int, y: int, w: int, h: int ) -> np.ndarray: """ Overlay the analyzed age and gender of face onto image itself Args: img (np.ndarray): image itself apparent_age (float): analyzed apparent age gender (st...
Overlay the analyzed age and gender of face onto image itself Args: img (np.ndarray): image itself apparent_age (float): analyzed apparent age gender (str): analyzed gender x (int): x coordinate of the face on the given image y (int): y coordinate of the face on the give...
overlay_age_gender
python
serengil/deepface
deepface/modules/streaming.py
https://github.com/serengil/deepface/blob/master/deepface/modules/streaming.py
MIT
def verify( img1_path: Union[str, np.ndarray, List[float]], img2_path: Union[str, np.ndarray, List[float]], model_name: str = "VGG-Face", detector_backend: str = "opencv", distance_metric: str = "cosine", enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, ...
Verify if an image pair represents the same person or different persons. The verification function converts facial images to vectors and calculates the similarity between those vectors. Vectors of images of the same person should exhibit higher similarity (or lower distance) than vectors of images of ...
verify
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def extract_embeddings_and_facial_areas( img_path: Union[str, np.ndarray, List[float]], index: int ) -> Tuple[List[List[float]], List[dict]]: """ Extracts facial embeddings and corresponding facial areas from an image or returns pre-calculated embeddings. Depending on the ty...
Extracts facial embeddings and corresponding facial areas from an image or returns pre-calculated embeddings. Depending on the type of img_path, the function either extracts facial embeddings from the provided image (via a path or NumPy array) or verifies that the input is a li...
extract_embeddings_and_facial_areas
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def __extract_faces_and_embeddings( img_path: Union[str, np.ndarray], model_name: str = "VGG-Face", detector_backend: str = "opencv", enforce_detection: bool = True, align: bool = True, expand_percentage: int = 0, normalization: str = "base", anti_spoofing: bool = False, ) -> Tuple[List[...
Extract facial areas and find corresponding embeddings for given image Returns: embeddings (List[float]) facial areas (List[dict])
__extract_faces_and_embeddings
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def find_cosine_distance( source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list] ) -> Union[np.float64, np.ndarray]: """ Find cosine distance between two given vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or bat...
Find cosine distance between two given vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or batch of vectors. test_representation (np.ndarray or list): 2nd vector or batch of vectors. Returns np.float64 or np.ndarray: Calculated cosine dista...
find_cosine_distance
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def find_angular_distance( source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list] ) -> Union[np.float64, np.ndarray]: """ Find angular distance between two vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or batch ...
Find angular distance between two vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or batch of vectors. test_representation (np.ndarray or list): 2nd vector or batch of vectors. Returns: np.float64 or np.ndarray: angular distance(s). ...
find_angular_distance
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def find_euclidean_distance( source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list] ) -> Union[np.float64, np.ndarray]: """ Find Euclidean distance between two vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or ba...
Find Euclidean distance between two vectors or batches of vectors. Args: source_representation (np.ndarray or list): 1st vector or batch of vectors. test_representation (np.ndarray or list): 2nd vector or batch of vectors. Returns: np.float64 or np.ndarray: Euclidean distance(s). ...
find_euclidean_distance
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def l2_normalize( x: Union[np.ndarray, list], axis: Union[int, None] = None, epsilon: float = 1e-10 ) -> np.ndarray: """ Normalize input vector with l2 Args: x (np.ndarray or list): given vector axis (int): axis along which to normalize Returns: np.ndarray: l2 normalized vect...
Normalize input vector with l2 Args: x (np.ndarray or list): given vector axis (int): axis along which to normalize Returns: np.ndarray: l2 normalized vector
l2_normalize
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def find_distance( alpha_embedding: Union[np.ndarray, list], beta_embedding: Union[np.ndarray, list], distance_metric: str, ) -> Union[np.float64, np.ndarray]: """ Wrapper to find the distance between vectors based on the specified distance metric. Args: alpha_embedding (np.ndarray or l...
Wrapper to find the distance between vectors based on the specified distance metric. Args: alpha_embedding (np.ndarray or list): 1st vector or batch of vectors. beta_embedding (np.ndarray or list): 2nd vector or batch of vectors. distance_metric (str): The type of distance to compute ...
find_distance
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def find_threshold(model_name: str, distance_metric: str) -> float: """ Retrieve pre-tuned threshold values for a model and distance metric pair Args: model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace an...
Retrieve pre-tuned threshold values for a model and distance metric pair Args: model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face). distance_metric (str): distan...
find_threshold
python
serengil/deepface
deepface/modules/verification.py
https://github.com/serengil/deepface/blob/master/deepface/modules/verification.py
MIT
def is_form_data_file_testable() -> bool: """ Sending a file from form data fails in unit test with 415 unsupported media type error for flask 3.X but it is working for flask 2.0.2 Returns: is_form_data_file_testable (bool) """ flask_version = version.parse(flask.__version__)...
Sending a file from form data fails in unit test with 415 unsupported media type error for flask 3.X but it is working for flask 2.0.2 Returns: is_form_data_file_testable (bool)
is_form_data_file_testable
python
serengil/deepface
tests/test_api.py
https://github.com/serengil/deepface/blob/master/tests/test_api.py
MIT
def test_filetype_for_find(): """ only images as jpg and png can be loaded into database """ img_path = os.path.join("dataset", "img1.jpg") dfs = DeepFace.find(img_path=img_path, db_path="dataset", silent=True) df = dfs[0] # img47 is webp even though its extension is jpg assert df[df["...
only images as jpg and png can be loaded into database
test_filetype_for_find
python
serengil/deepface
tests/test_find.py
https://github.com/serengil/deepface/blob/master/tests/test_find.py
MIT
def har_to_jar(cookiejar, har_cookies, request_cookies=None): """ Add HAR cookies to the cookiejar. If request_cookies is given, remove cookies absent from har_cookies but present in request_cookies (they were removed). """ har_cookie_keys = set() for c in har_cookies: cookie = har_to_cookie...
Add HAR cookies to the cookiejar. If request_cookies is given, remove cookies absent from har_cookies but present in request_cookies (they were removed).
har_to_jar
python
scrapy-plugins/scrapy-splash
scrapy_splash/cookies.py
https://github.com/scrapy-plugins/scrapy-splash/blob/master/scrapy_splash/cookies.py
BSD-3-Clause
def har_to_cookie(har_cookie): """ Convert a cookie dict in HAR format to a Cookie instance. >>> har_cookie = { ... "name": "TestCookie", ... "value": "Cookie Value", ... "path": "/foo", ... "domain": "www.janodvarko.cz", ... "expires": "2009-07-24T19:20:30Z", ....
Convert a cookie dict in HAR format to a Cookie instance. >>> har_cookie = { ... "name": "TestCookie", ... "value": "Cookie Value", ... "path": "/foo", ... "domain": "www.janodvarko.cz", ... "expires": "2009-07-24T19:20:30Z", ... "httpOnly": True, ... "...
har_to_cookie
python
scrapy-plugins/scrapy-splash
scrapy_splash/cookies.py
https://github.com/scrapy-plugins/scrapy-splash/blob/master/scrapy_splash/cookies.py
BSD-3-Clause