Skip to content

Commit 0c8e869

Browse files
committed
enforce tf 2.12 or less
1 parent 47363c6 commit 0c8e869

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

deepface/basemodels/FbDeepFace.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Flatten,
2424
Dense,
2525
Dropout,
26-
LocallyConnected2D,
2726
)
2827
else:
2928
from tensorflow.keras.models import Model, Sequential
@@ -33,7 +32,6 @@
3332
Flatten,
3433
Dense,
3534
Dropout,
36-
LocallyConnected2D,
3735
)
3836

3937

@@ -45,6 +43,14 @@ class DeepFaceClient(FacialRecognition):
4543
"""
4644

4745
def __init__(self):
46+
# DeepFace requires tf 2.12 or less
47+
if tf_major == 2 and tf_minor > 12:
48+
# Ref: https://github.com/serengil/deepface/pull/1079
49+
raise ValueError(
50+
"DeepFace model requires LocallyConnected2D but it is no longer supported"
51+
f" after tf 2.12 but you have {tf_major}.{tf_minor}. You need to downgrade your tf."
52+
)
53+
4854
self.model = load_model()
4955
self.model_name = "DeepFace"
5056
self.input_shape = (152, 152)
@@ -69,6 +75,13 @@ def load_model(
6975
"""
7076
Construct DeepFace model, download its weights and load
7177
"""
78+
# we have some checks for this dependency in the init of client
79+
# putting this in global causes library initialization
80+
if tf_major == 1:
81+
from keras.layers import LocallyConnected2D
82+
else:
83+
from tensorflow.keras.layers import LocallyConnected2D
84+
7285
base_model = Sequential()
7386
base_model.add(
7487
Convolution2D(32, (11, 11), activation="relu", name="C1", input_shape=(152, 152, 3))

0 commit comments

Comments
 (0)