mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
face region fixes
This commit is contained in:
parent
8af418d052
commit
97be78b004
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,5 +14,4 @@ deepface/commons/__pycache__/*
|
||||
deepface/basemodels/__pycache__/*
|
||||
deepface/extendedmodels/__pycache__/*
|
||||
deepface/subsidiarymodels/__pycache__/*
|
||||
tests/dataset/*.pkl
|
||||
Age_Gender_Retail_Analysis.ipynb
|
||||
tests/dataset/*.pkl
|
@ -282,12 +282,7 @@ def analyze(img_path, actions = ['emotion', 'age', 'gender', 'race']
|
||||
The function returns a dictionary. If img_path is a list, then it will return list of dictionary.
|
||||
|
||||
{
|
||||
"region": {
|
||||
'x': 230,
|
||||
'y': 120,
|
||||
'w': 36,
|
||||
'h': 45
|
||||
}
|
||||
"region": {'x': 230, 'y': 120, 'w': 36, 'h': 45},
|
||||
"age": 28.66,
|
||||
"gender": "woman",
|
||||
"dominant_emotion": "neutral",
|
||||
@ -370,7 +365,6 @@ def analyze(img_path, actions = ['emotion', 'age', 'gender', 'race']
|
||||
img_224 = None # Set to prevent re-detection
|
||||
|
||||
region = [] # x, y, w, h of the detected face region
|
||||
|
||||
region_labels = ['x', 'y', 'w', 'h']
|
||||
|
||||
#facial attribute analysis
|
||||
|
@ -190,6 +190,8 @@ def detect_face(img, detector_backend = 'opencv', grayscale = False, enforce_det
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
img_region = [0, 0, img.shape[0], img.shape[1]]
|
||||
|
||||
#if functions.preproces_face is called directly, then face_detector global variable might not been initialized.
|
||||
if not "face_detector" in globals():
|
||||
initialize_detector(detector_backend = detector_backend)
|
||||
@ -211,7 +213,7 @@ def detect_face(img, detector_backend = 'opencv', grayscale = False, enforce_det
|
||||
else: #if no face detected
|
||||
|
||||
if enforce_detection != True:
|
||||
return img
|
||||
return img, img_region
|
||||
|
||||
else:
|
||||
raise ValueError("Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.")
|
||||
@ -266,7 +268,7 @@ def detect_face(img, detector_backend = 'opencv', grayscale = False, enforce_det
|
||||
|
||||
if enforce_detection != True:
|
||||
img = base_img.copy()
|
||||
return img
|
||||
return img, img_region
|
||||
|
||||
else:
|
||||
raise ValueError("Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.")
|
||||
@ -288,7 +290,7 @@ def detect_face(img, detector_backend = 'opencv', grayscale = False, enforce_det
|
||||
else: #if no face detected
|
||||
|
||||
if enforce_detection != True:
|
||||
return img
|
||||
return img, img_region
|
||||
|
||||
else:
|
||||
raise ValueError("Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.")
|
||||
@ -306,7 +308,7 @@ def detect_face(img, detector_backend = 'opencv', grayscale = False, enforce_det
|
||||
|
||||
else: #if no face detected
|
||||
if not enforce_detection:
|
||||
return img
|
||||
return img, img_region
|
||||
|
||||
else:
|
||||
raise ValueError("Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.")
|
||||
|
@ -21,6 +21,9 @@ if tf_version == 2:
|
||||
|
||||
print("Running unit tests for TF ", tf.__version__)
|
||||
|
||||
from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace
|
||||
from deepface.extendedmodels import Age, Gender, Race, Emotion
|
||||
|
||||
#-----------------------------------------
|
||||
|
||||
dataset = [
|
||||
@ -200,27 +203,10 @@ else:
|
||||
raise ValueError("Unit test score does not satisfy the minimum required accuracy. Minimum expected score is ",threshold,"% but this got ",accuracy,"%")
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
# api tests - already built models will be passed to the functions
|
||||
|
||||
from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace
|
||||
|
||||
#-----------------------------------
|
||||
print("--------------------------")
|
||||
|
||||
print("Verify function with passing pre-trained model")
|
||||
|
||||
vggface_model = VGGFace.loadModel()
|
||||
resp_obj = DeepFace.verify("dataset/img1.jpg", "dataset/img2.jpg", model_name = "VGG-Face", model = vggface_model)
|
||||
print(resp_obj)
|
||||
|
||||
#-----------------------------------
|
||||
print("--------------------------")
|
||||
|
||||
print("Analyze function with passing pre-trained model")
|
||||
|
||||
from deepface.extendedmodels import Age, Gender, Race, Emotion
|
||||
|
||||
emotion_model = Emotion.loadModel()
|
||||
age_model = Age.loadModel()
|
||||
gender_model = Gender.loadModel()
|
||||
@ -257,7 +243,7 @@ for i in range(0, len(dataset)):
|
||||
#-----------------------------------
|
||||
print("--------------------------")
|
||||
|
||||
print("Pre-trained ensemble method")
|
||||
print("Pre-trained ensemble method - find")
|
||||
|
||||
from deepface import DeepFace
|
||||
from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace
|
||||
@ -272,10 +258,18 @@ print("OpenFace loaded")
|
||||
model["DeepFace"] = FbDeepFace.loadModel()
|
||||
print("DeepFace loaded")
|
||||
|
||||
df = DeepFace.find("dataset/img1.jpg", db_path = "dataset", model_name = 'Ensemble', model=model, enforce_detection=False)
|
||||
df = DeepFace.find("dataset/img1.jpg", db_path = "dataset", model_name = 'Ensemble', model = model, enforce_detection=False)
|
||||
|
||||
print(df)
|
||||
|
||||
#-----------------------------------
|
||||
print("--------------------------")
|
||||
|
||||
print("Pre-trained ensemble method - verify")
|
||||
res = DeepFace.verify(dataset, model_name = "Ensemble", model = model)
|
||||
print(res)
|
||||
|
||||
#-----------------------------------
|
||||
print("--------------------------")
|
||||
|
||||
import cv2
|
||||
|
Loading…
x
Reference in New Issue
Block a user