fix: rechecked with ultralitycs, embeddings generation is a bit misleading in terms of documentaion. In the end not suitable for recognition at all. Removed YoloFacialRecognition

This commit is contained in:
roberto-corno-nttdata 2024-12-10 16:00:43 +01:00
parent c25f14af10
commit f808126101
7 changed files with 15 additions and 119 deletions

View File

@ -54,8 +54,7 @@ def build_model(model_name: str, task: str = "facial_recognition") -> Any:
Args:
model_name (str): model identifier
- VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib,
ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n, Yolov11s and
Yolov11m for face recognition
ArcFace, SFace and GhostFaceNet for face recognition
- Age, Gender, Emotion, Race for facial attributes
- opencv, mtcnn, ssd, dlib, retinaface, mediapipe, yolov8, yolov11n,
yolov11s, yolov11m, yunet, fastmtcnn or centerface for face detectors
@ -94,8 +93,7 @@ def verify(
or pre-calculated embeddings.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m', 'centerface' or 'skip'
@ -291,8 +289,7 @@ def find(
in the database will be considered in the decision-making process.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
distance_metric (string): Metric for measuring similarity. Options: 'cosine',
'euclidean', 'euclidean_l2' (default is cosine).
@ -391,8 +388,7 @@ def represent(
include information for each detected face.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face.).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face.).
enforce_detection (boolean): If no face is detected in an image, raise an exception.
Default is True. Set to False to avoid the exception for low-resolution images
@ -462,8 +458,7 @@ def stream(
in the database will be considered in the decision-making process.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m',

View File

@ -1,88 +0,0 @@
# built-in dependencies
from typing import List, Any
from enum import Enum
# 3rd party dependencies
import numpy as np
# project dependencies
from deepface.models.FacialRecognition import FacialRecognition
from deepface.commons.logger import Logger
from deepface.commons import weight_utils
logger = Logger()
class YoloModel(Enum):
V8N = 0
V11N = 1
V11S = 2
V11M = 3
# Model's weights paths
WEIGHT_NAMES = ["yolov8n-face.pt",
"yolov11n-face.pt",
"yolov11s-face.pt",
"yolov11m-face.pt"]
# Google Drive URL from repo (https://github.com/derronqi/yolov8-face) ~6MB
WEIGHT_URLS = ["https://drive.google.com/uc?id=1qcr9DbgsX3ryrz2uU8w4Xm3cOrRywXqb",
"https://github.com/akanametov/yolo-face/releases/download/v0.0.0/yolov11n-face.pt",
"https://github.com/akanametov/yolo-face/releases/download/v0.0.0/yolov11s-face.pt",
"https://github.com/akanametov/yolo-face/releases/download/v0.0.0/yolov11m-face.pt"]
class YoloFacialRecognitionClient(FacialRecognition):
def __init__(self, model: YoloModel):
super().__init__()
self.model_name = "Yolo"
self.input_shape = (640, 640)
self.output_shape = 512
self.model = self.build_model(model)
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 ImportError(
"Yolo is an optional detector, ensure the library is installed. "
"Please install using 'pip install ultralytics'"
) from e
weight_file = weight_utils.download_weights_if_necessary(
file_name=WEIGHT_NAMES[model.value], source_url=WEIGHT_URLS[model.value]
)
# Return face_detector
return YOLO(weight_file)
def forward(self, img: np.ndarray) -> List[float]:
return self.model.embed(np.squeeze(img, axis=0))[0].tolist()
class YoloFacialRecognitionClientV8n(YoloFacialRecognitionClient):
def __init__(self):
super().__init__(YoloModel.V8N)
class YoloFacialRecognitionClientV11n(YoloFacialRecognitionClient):
def __init__(self):
super().__init__(YoloModel.V11N)
class YoloFacialRecognitionClientV11s(YoloFacialRecognitionClient):
def __init__(self):
super().__init__(YoloModel.V11S)
class YoloFacialRecognitionClientV11m(YoloFacialRecognitionClient):
def __init__(self):
super().__init__(YoloModel.V11M)

View File

@ -11,8 +11,7 @@ from deepface.models.facial_recognition import (
SFace,
Dlib,
Facenet,
GhostFaceNet,
Yolo as YoloFacialRecognition,
GhostFaceNet
)
from deepface.models.face_detection import (
FastMtCnn,
@ -37,7 +36,7 @@ def build_model(task: str, model_name: str) -> Any:
task (str): facial_recognition, facial_attribute, face_detector, spoofing
model_name (str): model identifier
- VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, Dlib,
ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n, Yolov11s and Yolov11m for face recognition
ArcFace, SFace and GhostFaceNet for face recognition
- Age, Gender, Emotion, Race for facial attributes
- opencv, mtcnn, ssd, dlib, retinaface, mediapipe, yolov8, 'yolov11n', 'yolov11s', 'yolov11m', yunet,
fastmtcnn or centerface for face detectors
@ -60,11 +59,7 @@ def build_model(task: str, model_name: str) -> Any:
"Dlib": Dlib.DlibClient,
"ArcFace": ArcFace.ArcFaceClient,
"SFace": SFace.SFaceClient,
"GhostFaceNet": GhostFaceNet.GhostFaceNetClient,
"Yolov8": YoloFacialRecognition.YoloFacialRecognitionClientV8n,
"Yolov11n": YoloFacialRecognition.YoloFacialRecognitionClientV11n,
"Yolov11s": YoloFacialRecognition.YoloFacialRecognitionClientV11s,
"Yolov11m": YoloFacialRecognition.YoloFacialRecognitionClientV11m
"GhostFaceNet": GhostFaceNet.GhostFaceNetClient
},
"spoofing": {
"Fasnet": FasNet.Fasnet,

View File

@ -45,8 +45,7 @@ def find(
in the database will be considered in the decision-making process.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
distance_metric (string): Metric for measuring similarity. Options: 'cosine',
'euclidean', 'euclidean_l2'.
@ -361,8 +360,7 @@ def __find_bulk_embeddings(
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, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
detector_backend (str): face detector model name
@ -477,8 +475,7 @@ def find_batched(
(used for anti-spoofing).
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
distance_metric (string): Metric for measuring similarity. Options: 'cosine',
'euclidean', 'euclidean_l2'.

View File

@ -30,7 +30,7 @@ def represent(
include information for each detected face.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n, Yolov11s and Yolov11m
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet
enforce_detection (boolean): If no face is detected in an image, raise an exception.
Default is True. Set to False to avoid the exception for low-resolution images.

View File

@ -42,8 +42,7 @@ def analysis(
in the database will be considered in the decision-making process.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face)
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m',
@ -191,8 +190,7 @@ def search_identity(
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, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m',
'centerface' or 'skip' (default is opencv).

View File

@ -44,8 +44,7 @@ def verify(
or pre-calculated embeddings.
model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace, GhostFaceNet, Yolov8, Yolov11n,
Yolov11s and Yolov11m (default is VGG-Face).
OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face).
detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8', 'yolov11n', 'yolov11s', 'yolov11m',