Skip to content

Commit

Permalink
Merge pull request #1134 from serengil/feat-task-2203-fbdeepface-bug
Browse files Browse the repository at this point in the history
enforce tf 2.12 or less
  • Loading branch information
serengil authored Mar 22, 2024
2 parents 47363c6 + 9957fe6 commit a3f04e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deepface/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.88"
__version__ = "0.0.89"
17 changes: 15 additions & 2 deletions deepface/basemodels/FbDeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Flatten,
Dense,
Dropout,
LocallyConnected2D,
)
else:
from tensorflow.keras.models import Model, Sequential
Expand All @@ -33,7 +32,6 @@
Flatten,
Dense,
Dropout,
LocallyConnected2D,
)


Expand All @@ -45,6 +43,14 @@ class DeepFaceClient(FacialRecognition):
"""

def __init__(self):
# DeepFace requires tf 2.12 or less
if tf_major == 2 and tf_minor > 12:
# Ref: https://github.com/serengil/deepface/pull/1079
raise ValueError(
"DeepFace model requires LocallyConnected2D but it is no longer supported"
f" after tf 2.12 but you have {tf_major}.{tf_minor}. You need to downgrade your tf."
)

self.model = load_model()
self.model_name = "DeepFace"
self.input_shape = (152, 152)
Expand All @@ -69,6 +75,13 @@ def load_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 LocallyConnected2D
else:
from tensorflow.keras.layers import LocallyConnected2D

base_model = Sequential()
base_model.add(
Convolution2D(32, (11, 11), activation="relu", name="C1", input_shape=(152, 152, 3))
Expand Down
2 changes: 1 addition & 1 deletion package_info.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.0.88"
"version": "0.0.89"
}

0 comments on commit a3f04e6

Please sign in to comment.