Skip to content

Commit

Permalink
batch run support added for facial attribute models
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Aug 4, 2024
1 parent 62055d0 commit 51717db
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion deepface/extendedmodels/Age.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def __init__(self):
self.model_name = "Age"

def predict(self, img: np.ndarray) -> np.float64:
age_predictions = self.model.predict(img, verbose=0)[0, :]
# model.predict causes memory issue when it is called in a for loop
# age_predictions = self.model.predict(img, verbose=0)[0, :]
age_predictions = self.model(img, training=False).numpy()[0, :]
return find_apparent_age(age_predictions)


Expand Down
5 changes: 4 additions & 1 deletion deepface/extendedmodels/Emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def predict(self, img: np.ndarray) -> np.ndarray:
img_gray = cv2.resize(img_gray, (48, 48))
img_gray = np.expand_dims(img_gray, axis=0)

emotion_predictions = self.model.predict(img_gray, verbose=0)[0, :]
# model.predict causes memory issue when it is called in a for loop
# emotion_predictions = self.model.predict(img_gray, verbose=0)[0, :]
emotion_predictions = self.model(img_gray, training=False).numpy()[0, :]

return emotion_predictions


Expand Down
4 changes: 3 additions & 1 deletion deepface/extendedmodels/Gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def __init__(self):
self.model_name = "Gender"

def predict(self, img: np.ndarray) -> np.ndarray:
return self.model.predict(img, verbose=0)[0, :]
# model.predict causes memory issue when it is called in a for loop
# return self.model.predict(img, verbose=0)[0, :]
return self.model(img, training=False).numpy()[0, :]


def load_model(
Expand Down
4 changes: 3 additions & 1 deletion deepface/extendedmodels/Race.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def __init__(self):
self.model_name = "Race"

def predict(self, img: np.ndarray) -> np.ndarray:
return self.model.predict(img, verbose=0)[0, :]
# model.predict causes memory issue when it is called in a for loop
# return self.model.predict(img, verbose=0)[0, :]
return self.model(img, training=False).numpy()[0, :]


def load_model(
Expand Down

0 comments on commit 51717db

Please sign in to comment.