mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 03:55:21 +00:00
all models can be downloaded with one shot
This commit is contained in:
parent
5415407b7c
commit
234d0db6c5
@ -11,6 +11,33 @@ import gdown
|
|||||||
from deepface.commons import folder_utils, package_utils
|
from deepface.commons import folder_utils, package_utils
|
||||||
from deepface.commons.logger import Logger
|
from deepface.commons.logger import Logger
|
||||||
|
|
||||||
|
# weight urls as variables
|
||||||
|
from deepface.models.facial_recognition.VGGFace import WEIGHTS_URL as VGGFACE_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.Facenet import FACENET128_WEIGHTS, FACENET512_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.OpenFace import WEIGHTS_URL as OPENFACE_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.FbDeepFace import WEIGHTS_URL as FBDEEPFACE_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.ArcFace import WEIGHTS_URL as ARCFACE_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.DeepID import WEIGHTS_URL as DEEPID_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.SFace import WEIGHTS_URL as SFACE_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.GhostFaceNet import WEIGHTS_URL as GHOSTFACENET_WEIGHTS
|
||||||
|
from deepface.models.facial_recognition.Dlib import WEIGHT_URL as DLIB_FR_WEIGHTS
|
||||||
|
from deepface.models.demography.Age import WEIGHTS_URL as AGE_WEIGHTS
|
||||||
|
from deepface.models.demography.Gender import WEIGHTS_URL as GENDER_WEIGHTS
|
||||||
|
from deepface.models.demography.Race import WEIGHTS_URL as RACE_WEIGHTS
|
||||||
|
from deepface.models.demography.Emotion import WEIGHTS_URL as EMOTION_WEIGHTS
|
||||||
|
from deepface.models.spoofing.FasNet import (
|
||||||
|
FIRST_WEIGHTS_URL as FASNET_1ST_WEIGHTS,
|
||||||
|
SECOND_WEIGHTS_URL as FASNET_2ND_WEIGHTS,
|
||||||
|
)
|
||||||
|
from deepface.models.face_detection.Ssd import MODEL_URL as SSD_MODEL, WEIGHTS_URL as SSD_WEIGHTS
|
||||||
|
from deepface.models.face_detection.Yolo import (
|
||||||
|
WEIGHT_URL as YOLOV8_WEIGHTS,
|
||||||
|
WEIGHT_NAME as YOLOV8_WEIGHT_NAME,
|
||||||
|
)
|
||||||
|
from deepface.models.face_detection.YuNet import WEIGHTS_URL as YUNET_WEIGHTS
|
||||||
|
from deepface.models.face_detection.Dlib import WEIGHTS_URL as DLIB_FD_WEIGHTS
|
||||||
|
from deepface.models.face_detection.CenterFace import WEIGHTS_URL as CENTERFACE_WEIGHTS
|
||||||
|
|
||||||
tf_version = package_utils.get_tf_major_version()
|
tf_version = package_utils.get_tf_major_version()
|
||||||
if tf_version == 1:
|
if tf_version == 1:
|
||||||
from keras.models import Sequential
|
from keras.models import Sequential
|
||||||
@ -20,38 +47,40 @@ else:
|
|||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
WEIGHTS = {
|
WEIGHTS = [
|
||||||
"facial_recognition": {
|
# facial recognition
|
||||||
"VGG-Face": "https://github.com/serengil/deepface_models/releases/download/v1.0/vgg_face_weights.h5",
|
VGGFACE_WEIGHTS,
|
||||||
"Facenet": "https://github.com/serengil/deepface_models/releases/download/v1.0/facenet_weights.h5",
|
FACENET128_WEIGHTS,
|
||||||
"Facenet512": "https://github.com/serengil/deepface_models/releases/download/v1.0/facenet512_weights.h5",
|
FACENET512_WEIGHTS,
|
||||||
"OpenFace": "https://github.com/serengil/deepface_models/releases/download/v1.0/openface_weights.h5",
|
OPENFACE_WEIGHTS,
|
||||||
"FbDeepFace": "https://github.com/swghosh/DeepFace/releases/download/weights-vggface2-2d-aligned/VGGFace2_DeepFace_weights_val-0.9034.h5.zip",
|
FBDEEPFACE_WEIGHTS,
|
||||||
"ArcFace": "https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5",
|
ARCFACE_WEIGHTS,
|
||||||
"DeepID": "https://github.com/serengil/deepface_models/releases/download/v1.0/deepid_keras_weights.h5",
|
DEEPID_WEIGHTS,
|
||||||
"SFace": "https://github.com/opencv/opencv_zoo/raw/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx",
|
SFACE_WEIGHTS,
|
||||||
"GhostFaceNet": "https://github.com/HamadYA/GhostFaceNets/releases/download/v1.2/GhostFaceNet_W1.3_S1_ArcFace.h5",
|
{
|
||||||
"Dlib": "http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2",
|
"filename": "ghostfacenet_v1.h5",
|
||||||
|
"url": GHOSTFACENET_WEIGHTS,
|
||||||
},
|
},
|
||||||
"demography": {
|
DLIB_FR_WEIGHTS,
|
||||||
"Age": "https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5",
|
# demography
|
||||||
"Gender": "https://github.com/serengil/deepface_models/releases/download/v1.0/gender_model_weights.h5",
|
AGE_WEIGHTS,
|
||||||
"Emotion": "https://github.com/serengil/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5",
|
GENDER_WEIGHTS,
|
||||||
"Race": "https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5",
|
RACE_WEIGHTS,
|
||||||
|
EMOTION_WEIGHTS,
|
||||||
|
# spoofing
|
||||||
|
FASNET_1ST_WEIGHTS,
|
||||||
|
FASNET_2ND_WEIGHTS,
|
||||||
|
# face detection
|
||||||
|
SSD_MODEL,
|
||||||
|
SSD_WEIGHTS,
|
||||||
|
{
|
||||||
|
"filename": YOLOV8_WEIGHT_NAME,
|
||||||
|
"url": YOLOV8_WEIGHTS,
|
||||||
},
|
},
|
||||||
"detection": {
|
YUNET_WEIGHTS,
|
||||||
"ssd_model": "https://github.com/opencv/opencv/raw/3.4.0/samples/dnn/face_detector/deploy.prototxt",
|
DLIB_FD_WEIGHTS,
|
||||||
"ssd_weights": "https://github.com/opencv/opencv_3rdparty/raw/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel",
|
CENTERFACE_WEIGHTS,
|
||||||
"yolo": "https://drive.google.com/uc?id=1qcr9DbgsX3ryrz2uU8w4Xm3cOrRywXqb",
|
]
|
||||||
"yunet": "https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx",
|
|
||||||
"dlib": "http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2",
|
|
||||||
"centerface": "https://github.com/Star-Clouds/CenterFace/raw/master/models/onnx/centerface.onnx",
|
|
||||||
},
|
|
||||||
"spoofing": {
|
|
||||||
"MiniFASNetV2": "https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/2.7_80x80_MiniFASNetV2.pth",
|
|
||||||
"MiniFASNetV1SE": "https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/4_0_0_80x80_MiniFASNetV1SE.pth",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ALLOWED_COMPRESS_TYPES = ["zip", "bz2"]
|
ALLOWED_COMPRESS_TYPES = ["zip", "bz2"]
|
||||||
|
|
||||||
@ -131,18 +160,30 @@ def load_model_weights(model: Sequential, weight_file: str) -> Sequential:
|
|||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
def retrieve_model_source(model_name: str, task: str) -> str:
|
def download_all_models_in_one_shot() -> None:
|
||||||
"""
|
"""
|
||||||
Find the source url of a given model name
|
Download all model weights in one shot
|
||||||
Args:
|
|
||||||
model_name (str): given model name
|
|
||||||
Returns:
|
|
||||||
weight_url (str): source url of the given model
|
|
||||||
"""
|
"""
|
||||||
if task not in ["facial_recognition", "detection", "demography", "spoofing"]:
|
for i in WEIGHTS:
|
||||||
raise ValueError(f"unimplemented task - {task}")
|
if isinstance(i, str):
|
||||||
|
url = i
|
||||||
source_url = WEIGHTS.get(task, {}).get(model_name)
|
filename = i.split("/")[-1]
|
||||||
if source_url is None:
|
compress_type = None
|
||||||
raise ValueError(f"Source url cannot be found for given model {task}-{model_name}")
|
# if compressed file will be downloaded, get rid of its extension
|
||||||
return source_url
|
if filename.endswith(tuple(ALLOWED_COMPRESS_TYPES)):
|
||||||
|
for ext in ALLOWED_COMPRESS_TYPES:
|
||||||
|
compress_type = ext
|
||||||
|
if filename.endswith(f".{ext}"):
|
||||||
|
filename = filename[: -(len(ext) + 1)]
|
||||||
|
break
|
||||||
|
elif isinstance(i, dict):
|
||||||
|
filename = i["filename"]
|
||||||
|
url = i["url"]
|
||||||
|
else:
|
||||||
|
raise ValueError("unimplemented scenario")
|
||||||
|
logger.info(
|
||||||
|
f"Downloading {url} to ~/.deepface/weights/{filename} with {compress_type} compression"
|
||||||
|
)
|
||||||
|
download_weights_if_necessary(
|
||||||
|
file_name=filename, source_url=url, compress_type=compress_type
|
||||||
|
)
|
||||||
|
@ -23,6 +23,10 @@ else:
|
|||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
|
|
||||||
|
WEIGHTS_URL = (
|
||||||
|
"https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5"
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class ApparentAgeClient(Demography):
|
class ApparentAgeClient(Demography):
|
||||||
"""
|
"""
|
||||||
@ -41,7 +45,7 @@ class ApparentAgeClient(Demography):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct age model, download its weights and load
|
Construct age model, download its weights and load
|
||||||
@ -70,12 +74,11 @@ def load_model(
|
|||||||
file_name="age_model_weights.h5", source_url=url
|
file_name="age_model_weights.h5", source_url=url
|
||||||
)
|
)
|
||||||
|
|
||||||
age_model = weight_utils.load_model_weights(
|
age_model = weight_utils.load_model_weights(model=age_model, weight_file=weight_file)
|
||||||
model=age_model, weight_file=weight_file
|
|
||||||
)
|
|
||||||
|
|
||||||
return age_model
|
return age_model
|
||||||
|
|
||||||
|
|
||||||
def find_apparent_age(age_predictions: np.ndarray) -> np.float64:
|
def find_apparent_age(age_predictions: np.ndarray) -> np.float64:
|
||||||
"""
|
"""
|
||||||
Find apparent age prediction from a given probas of ages
|
Find apparent age prediction from a given probas of ages
|
||||||
|
@ -7,11 +7,6 @@ from deepface.commons import package_utils, weight_utils
|
|||||||
from deepface.models.Demography import Demography
|
from deepface.models.Demography import Demography
|
||||||
from deepface.commons.logger import Logger
|
from deepface.commons.logger import Logger
|
||||||
|
|
||||||
logger = Logger()
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# pylint: disable=line-too-long
|
|
||||||
# -------------------------------------------
|
|
||||||
# dependency configuration
|
# dependency configuration
|
||||||
tf_version = package_utils.get_tf_major_version()
|
tf_version = package_utils.get_tf_major_version()
|
||||||
|
|
||||||
@ -28,12 +23,17 @@ else:
|
|||||||
Dense,
|
Dense,
|
||||||
Dropout,
|
Dropout,
|
||||||
)
|
)
|
||||||
# -------------------------------------------
|
|
||||||
|
|
||||||
# Labels for the emotions that can be detected by the model.
|
# Labels for the emotions that can be detected by the model.
|
||||||
labels = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]
|
labels = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
logger = Logger()
|
||||||
|
|
||||||
|
# pylint: disable=line-too-long, disable=too-few-public-methods
|
||||||
|
|
||||||
|
WEIGHTS_URL = "https://github.com/serengil/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5"
|
||||||
|
|
||||||
|
|
||||||
class EmotionClient(Demography):
|
class EmotionClient(Demography):
|
||||||
"""
|
"""
|
||||||
Emotion model class
|
Emotion model class
|
||||||
@ -56,7 +56,7 @@ class EmotionClient(Demography):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Sequential:
|
) -> Sequential:
|
||||||
"""
|
"""
|
||||||
Consruct emotion model, download and load weights
|
Consruct emotion model, download and load weights
|
||||||
@ -96,8 +96,6 @@ def load_model(
|
|||||||
file_name="facial_expression_model_weights.h5", source_url=url
|
file_name="facial_expression_model_weights.h5", source_url=url
|
||||||
)
|
)
|
||||||
|
|
||||||
model = weight_utils.load_model_weights(
|
model = weight_utils.load_model_weights(model=model, weight_file=weight_file)
|
||||||
model=model, weight_file=weight_file
|
|
||||||
)
|
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
@ -21,7 +21,8 @@ if tf_version == 1:
|
|||||||
else:
|
else:
|
||||||
from tensorflow.keras.models import Model, Sequential
|
from tensorflow.keras.models import Model, Sequential
|
||||||
from tensorflow.keras.layers import Convolution2D, Flatten, Activation
|
from tensorflow.keras.layers import Convolution2D, Flatten, Activation
|
||||||
# -------------------------------------
|
|
||||||
|
WEIGHTS_URL="https://github.com/serengil/deepface_models/releases/download/v1.0/gender_model_weights.h5"
|
||||||
|
|
||||||
# Labels for the genders that can be detected by the model.
|
# Labels for the genders that can be detected by the model.
|
||||||
labels = ["Woman", "Man"]
|
labels = ["Woman", "Man"]
|
||||||
@ -43,7 +44,7 @@ class GenderClient(Demography):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/gender_model_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct gender model, download its weights and load
|
Construct gender model, download its weights and load
|
||||||
|
@ -7,11 +7,8 @@ from deepface.commons import package_utils, weight_utils
|
|||||||
from deepface.models.Demography import Demography
|
from deepface.models.Demography import Demography
|
||||||
from deepface.commons.logger import Logger
|
from deepface.commons.logger import Logger
|
||||||
|
|
||||||
logger = Logger()
|
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
# --------------------------
|
|
||||||
# dependency configurations
|
# dependency configurations
|
||||||
tf_version = package_utils.get_tf_major_version()
|
tf_version = package_utils.get_tf_major_version()
|
||||||
|
|
||||||
@ -21,10 +18,15 @@ if tf_version == 1:
|
|||||||
else:
|
else:
|
||||||
from tensorflow.keras.models import Model, Sequential
|
from tensorflow.keras.models import Model, Sequential
|
||||||
from tensorflow.keras.layers import Convolution2D, Flatten, Activation
|
from tensorflow.keras.layers import Convolution2D, Flatten, Activation
|
||||||
# --------------------------
|
|
||||||
|
WEIGHTS_URL = (
|
||||||
|
"https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5"
|
||||||
|
)
|
||||||
# Labels for the ethnic phenotypes that can be detected by the model.
|
# Labels for the ethnic phenotypes that can be detected by the model.
|
||||||
labels = ["asian", "indian", "black", "white", "middle eastern", "latino hispanic"]
|
labels = ["asian", "indian", "black", "white", "middle eastern", "latino hispanic"]
|
||||||
|
|
||||||
|
logger = Logger()
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class RaceClient(Demography):
|
class RaceClient(Demography):
|
||||||
"""
|
"""
|
||||||
@ -42,7 +44,7 @@ class RaceClient(Demography):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct race model, download its weights and load
|
Construct race model, download its weights and load
|
||||||
@ -69,8 +71,6 @@ def load_model(
|
|||||||
file_name="race_model_single_batch.h5", source_url=url
|
file_name="race_model_single_batch.h5", source_url=url
|
||||||
)
|
)
|
||||||
|
|
||||||
race_model = weight_utils.load_model_weights(
|
race_model = weight_utils.load_model_weights(model=race_model, weight_file=weight_file)
|
||||||
model=race_model, weight_file=weight_file
|
|
||||||
)
|
|
||||||
|
|
||||||
return race_model
|
return race_model
|
||||||
|
@ -11,6 +11,7 @@ from deepface.commons.logger import Logger
|
|||||||
|
|
||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
|
WEIGHTS_URL="http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2"
|
||||||
|
|
||||||
class DlibClient(Detector):
|
class DlibClient(Detector):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -34,7 +35,7 @@ class DlibClient(Detector):
|
|||||||
# check required file exists in the home/.deepface/weights folder
|
# check required file exists in the home/.deepface/weights folder
|
||||||
weight_file = weight_utils.download_weights_if_necessary(
|
weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="shape_predictor_5_face_landmarks.dat",
|
file_name="shape_predictor_5_face_landmarks.dat",
|
||||||
source_url="http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2",
|
source_url=WEIGHTS_URL,
|
||||||
compress_type="bz2",
|
compress_type="bz2",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ logger = Logger()
|
|||||||
|
|
||||||
# pylint: disable=line-too-long, c-extension-no-member
|
# pylint: disable=line-too-long, c-extension-no-member
|
||||||
|
|
||||||
|
MODEL_URL = "https://github.com/opencv/opencv/raw/3.4.0/samples/dnn/face_detector/deploy.prototxt"
|
||||||
|
WEIGHTS_URL = "https://github.com/opencv/opencv_3rdparty/raw/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel"
|
||||||
|
|
||||||
|
|
||||||
class SsdClient(Detector):
|
class SsdClient(Detector):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -31,13 +34,13 @@ class SsdClient(Detector):
|
|||||||
# model structure
|
# model structure
|
||||||
output_model = weight_utils.download_weights_if_necessary(
|
output_model = weight_utils.download_weights_if_necessary(
|
||||||
file_name="deploy.prototxt",
|
file_name="deploy.prototxt",
|
||||||
source_url="https://github.com/opencv/opencv/raw/3.4.0/samples/dnn/face_detector/deploy.prototxt",
|
source_url=MODEL_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
# pre-trained weights
|
# pre-trained weights
|
||||||
output_weights = weight_utils.download_weights_if_necessary(
|
output_weights = weight_utils.download_weights_if_necessary(
|
||||||
file_name="res10_300x300_ssd_iter_140000.caffemodel",
|
file_name="res10_300x300_ssd_iter_140000.caffemodel",
|
||||||
source_url="https://github.com/opencv/opencv_3rdparty/raw/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel",
|
source_url=WEIGHTS_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -12,7 +12,7 @@ from deepface.commons.logger import Logger
|
|||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
# Model's weights paths
|
# Model's weights paths
|
||||||
PATH = ".deepface/weights/yolov8n-face.pt"
|
WEIGHT_NAME = "yolov8n-face.pt"
|
||||||
|
|
||||||
# Google Drive URL from repo (https://github.com/derronqi/yolov8-face) ~6MB
|
# Google Drive URL from repo (https://github.com/derronqi/yolov8-face) ~6MB
|
||||||
WEIGHT_URL = "https://drive.google.com/uc?id=1qcr9DbgsX3ryrz2uU8w4Xm3cOrRywXqb"
|
WEIGHT_URL = "https://drive.google.com/uc?id=1qcr9DbgsX3ryrz2uU8w4Xm3cOrRywXqb"
|
||||||
@ -39,7 +39,7 @@ class YoloClient(Detector):
|
|||||||
) from e
|
) from e
|
||||||
|
|
||||||
weight_file = weight_utils.download_weights_if_necessary(
|
weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="yolov8n-face.pt", source_url=WEIGHT_URL
|
file_name=WEIGHT_NAME, source_url=WEIGHT_URL
|
||||||
)
|
)
|
||||||
|
|
||||||
# Return face_detector
|
# Return face_detector
|
||||||
|
@ -13,6 +13,8 @@ from deepface.commons.logger import Logger
|
|||||||
|
|
||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
|
WEIGHTS_URL = "https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx"
|
||||||
|
|
||||||
|
|
||||||
class YuNetClient(Detector):
|
class YuNetClient(Detector):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -41,7 +43,7 @@ class YuNetClient(Detector):
|
|||||||
# pylint: disable=C0301
|
# pylint: disable=C0301
|
||||||
weight_file = weight_utils.download_weights_if_necessary(
|
weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="face_detection_yunet_2023mar.onnx",
|
file_name="face_detection_yunet_2023mar.onnx",
|
||||||
source_url="https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx",
|
source_url=WEIGHTS_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -42,6 +42,8 @@ else:
|
|||||||
Dense,
|
Dense,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
WEIGHTS_URL="https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5"
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class ArcFaceClient(FacialRecognition):
|
class ArcFaceClient(FacialRecognition):
|
||||||
"""
|
"""
|
||||||
@ -56,7 +58,7 @@ class ArcFaceClient(FacialRecognition):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct ArcFace model, download its weights and load
|
Construct ArcFace model, download its weights and load
|
||||||
|
@ -34,8 +34,7 @@ else:
|
|||||||
|
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
|
|
||||||
|
WEIGHTS_URL="https://github.com/serengil/deepface_models/releases/download/v1.0/deepid_keras_weights.h5"
|
||||||
# -------------------------------------
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class DeepIdClient(FacialRecognition):
|
class DeepIdClient(FacialRecognition):
|
||||||
@ -51,7 +50,7 @@ class DeepIdClient(FacialRecognition):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/deepid_keras_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct DeepId model, download its weights and load
|
Construct DeepId model, download its weights and load
|
||||||
|
@ -12,6 +12,7 @@ from deepface.commons.logger import Logger
|
|||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
WEIGHT_URL = "http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2"
|
||||||
|
|
||||||
|
|
||||||
class DlibClient(FacialRecognition):
|
class DlibClient(FacialRecognition):
|
||||||
@ -70,7 +71,7 @@ class DlibResNet:
|
|||||||
|
|
||||||
weight_file = weight_utils.download_weights_if_necessary(
|
weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="dlib_face_recognition_resnet_model_v1.dat",
|
file_name="dlib_face_recognition_resnet_model_v1.dat",
|
||||||
source_url="http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2",
|
source_url=WEIGHT_URL,
|
||||||
compress_type="bz2",
|
compress_type="bz2",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ else:
|
|||||||
from tensorflow.keras.layers import add
|
from tensorflow.keras.layers import add
|
||||||
from tensorflow.keras import backend as K
|
from tensorflow.keras import backend as K
|
||||||
|
|
||||||
|
FACENET128_WEIGHTS="https://github.com/serengil/deepface_models/releases/download/v1.0/facenet_weights.h5"
|
||||||
|
FACENET512_WEIGHTS="https://github.com/serengil/deepface_models/releases/download/v1.0/facenet512_weights.h5"
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -1654,7 +1657,7 @@ def InceptionResNetV1(dimension: int = 128) -> Model:
|
|||||||
|
|
||||||
|
|
||||||
def load_facenet128d_model(
|
def load_facenet128d_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/facenet_weights.h5",
|
url=FACENET128_WEIGHTS,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct FaceNet-128d model, download weights and then load weights
|
Construct FaceNet-128d model, download weights and then load weights
|
||||||
@ -1676,7 +1679,7 @@ def load_facenet128d_model(
|
|||||||
|
|
||||||
|
|
||||||
def load_facenet512d_model(
|
def load_facenet512d_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/facenet512_weights.h5",
|
url=FACENET512_WEIGHTS,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct FaceNet-512d model, download its weights and load
|
Construct FaceNet-512d model, download its weights and load
|
||||||
|
@ -30,6 +30,7 @@ else:
|
|||||||
Dropout,
|
Dropout,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
WEIGHTS_URL="https://github.com/swghosh/DeepFace/releases/download/weights-vggface2-2d-aligned/VGGFace2_DeepFace_weights_val-0.9034.h5.zip"
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
# pylint: disable=line-too-long, too-few-public-methods
|
# pylint: disable=line-too-long, too-few-public-methods
|
||||||
@ -54,7 +55,7 @@ class DeepFaceClient(FacialRecognition):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/swghosh/DeepFace/releases/download/weights-vggface2-2d-aligned/VGGFace2_DeepFace_weights_val-0.9034.h5.zip",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Construct DeepFace model, download its weights and load
|
Construct DeepFace model, download its weights and load
|
||||||
|
@ -48,7 +48,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
# pylint: disable=line-too-long, too-few-public-methods, no-else-return, unsubscriptable-object, comparison-with-callable
|
# pylint: disable=line-too-long, too-few-public-methods, no-else-return, unsubscriptable-object, comparison-with-callable
|
||||||
PRETRAINED_WEIGHTS = "https://github.com/HamadYA/GhostFaceNets/releases/download/v1.2/GhostFaceNet_W1.3_S1_ArcFace.h5"
|
WEIGHTS_URL = "https://github.com/HamadYA/GhostFaceNets/releases/download/v1.2/GhostFaceNet_W1.3_S1_ArcFace.h5"
|
||||||
|
|
||||||
|
|
||||||
class GhostFaceNetClient(FacialRecognition):
|
class GhostFaceNetClient(FacialRecognition):
|
||||||
@ -71,12 +71,10 @@ def load_model():
|
|||||||
model = GhostFaceNetV1()
|
model = GhostFaceNetV1()
|
||||||
|
|
||||||
weight_file = weight_utils.download_weights_if_necessary(
|
weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="ghostfacenet_v1.h5", source_url=PRETRAINED_WEIGHTS
|
file_name="ghostfacenet_v1.h5", source_url=WEIGHTS_URL
|
||||||
)
|
)
|
||||||
|
|
||||||
model = weight_utils.load_model_weights(
|
model = weight_utils.load_model_weights(model=model, weight_file=weight_file)
|
||||||
model=model, weight_file=weight_file
|
|
||||||
)
|
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ else:
|
|||||||
|
|
||||||
# pylint: disable=unnecessary-lambda
|
# pylint: disable=unnecessary-lambda
|
||||||
|
|
||||||
|
WEIGHTS_URL="https://github.com/serengil/deepface_models/releases/download/v1.0/openface_weights.h5"
|
||||||
|
|
||||||
# ---------------------------------------
|
# ---------------------------------------
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -40,7 +42,7 @@ class OpenFaceClient(FacialRecognition):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/openface_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Consturct OpenFace model, download its weights and load
|
Consturct OpenFace model, download its weights and load
|
||||||
|
@ -13,6 +13,7 @@ from deepface.commons.logger import Logger
|
|||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
# pylint: disable=line-too-long, too-few-public-methods
|
# pylint: disable=line-too-long, too-few-public-methods
|
||||||
|
WEIGHTS_URL = "https://github.com/opencv/opencv_zoo/raw/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx"
|
||||||
|
|
||||||
|
|
||||||
class SFaceClient(FacialRecognition):
|
class SFaceClient(FacialRecognition):
|
||||||
@ -47,7 +48,7 @@ class SFaceClient(FacialRecognition):
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/opencv/opencv_zoo/raw/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx",
|
url=WEIGHTS_URL,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
Construct SFace model, download its weights and load
|
Construct SFace model, download its weights and load
|
||||||
|
@ -38,6 +38,10 @@ else:
|
|||||||
|
|
||||||
# ---------------------------------------
|
# ---------------------------------------
|
||||||
|
|
||||||
|
WEIGHTS_URL = (
|
||||||
|
"https://github.com/serengil/deepface_models/releases/download/v1.0/vgg_face_weights.h5"
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class VggFaceClient(FacialRecognition):
|
class VggFaceClient(FacialRecognition):
|
||||||
"""
|
"""
|
||||||
@ -126,7 +130,7 @@ def base_model() -> Sequential:
|
|||||||
|
|
||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
url="https://github.com/serengil/deepface_models/releases/download/v1.0/vgg_face_weights.h5",
|
url=WEIGHTS_URL,
|
||||||
) -> Model:
|
) -> Model:
|
||||||
"""
|
"""
|
||||||
Final VGG-Face model being used for finding embeddings
|
Final VGG-Face model being used for finding embeddings
|
||||||
|
@ -12,6 +12,9 @@ from deepface.commons.logger import Logger
|
|||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
# pylint: disable=line-too-long, too-few-public-methods, nested-min-max
|
# pylint: disable=line-too-long, too-few-public-methods, nested-min-max
|
||||||
|
FIRST_WEIGHTS_URL="https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/2.7_80x80_MiniFASNetV2.pth"
|
||||||
|
SECOND_WEIGHTS_URL="https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/4_0_0_80x80_MiniFASNetV1SE.pth"
|
||||||
|
|
||||||
class Fasnet:
|
class Fasnet:
|
||||||
"""
|
"""
|
||||||
Mini Face Anti Spoofing Net Library from repo: github.com/minivision-ai/Silent-Face-Anti-Spoofing
|
Mini Face Anti Spoofing Net Library from repo: github.com/minivision-ai/Silent-Face-Anti-Spoofing
|
||||||
@ -35,12 +38,12 @@ class Fasnet:
|
|||||||
# download pre-trained models if not installed yet
|
# download pre-trained models if not installed yet
|
||||||
first_model_weight_file = weight_utils.download_weights_if_necessary(
|
first_model_weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="2.7_80x80_MiniFASNetV2.pth",
|
file_name="2.7_80x80_MiniFASNetV2.pth",
|
||||||
source_url="https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/2.7_80x80_MiniFASNetV2.pth",
|
source_url=FIRST_WEIGHTS_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
second_model_weight_file = weight_utils.download_weights_if_necessary(
|
second_model_weight_file = weight_utils.download_weights_if_necessary(
|
||||||
file_name="4_0_0_80x80_MiniFASNetV1SE.pth",
|
file_name="4_0_0_80x80_MiniFASNetV1SE.pth",
|
||||||
source_url="https://github.com/minivision-ai/Silent-Face-Anti-Spoofing/raw/master/resources/anti_spoof_models/4_0_0_80x80_MiniFASNetV1SE.pth",
|
source_url=SECOND_WEIGHTS_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
# guarantees Fasnet imported and torch installed
|
# guarantees Fasnet imported and torch installed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user