Skip to content

Commit

Permalink
LocallyConnected2D not supported after tf 2.12
Browse files Browse the repository at this point in the history
- this requirements is just for deepface model. so, instead of enforcing lower tf versions
we should check the current tf version in deepface model initializaiton.
  • Loading branch information
serengil committed Mar 9, 2024
1 parent 46f0141 commit 65c47ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions deepface/basemodels/FbDeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class DeepFaceClient(FacialRecognition):
"""

def __init__(self):
major = package_utils.get_tf_major_version()
minor = package_utils.get_tf_minor_version()
if major == 2 and 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 {major}.{minor}. You need to downgrade your tf."
)

self.model = load_model()
self.model_name = "DeepFace"
self.input_shape = (152, 152)
Expand Down
9 changes: 9 additions & 0 deletions deepface/commons/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ def get_tf_major_version() -> int:
return int(tf.__version__.split(".", maxsplit=1)[0])


def get_tf_minor_version() -> int:
"""
Find tensorflow's minor version
Returns
minor_version (int)
"""
return int(tf.__version__.split(".", maxsplit=-1)[1])


def find_hash_of_file(file_path: str) -> str:
"""
Find the hash of given image file with its properties
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gdown>=3.10.1
tqdm>=4.30.0
Pillow>=5.2.0
opencv-python>=4.5.5.64
tensorflow>=1.9.0,<=2.12.0
tensorflow>=1.9.0
keras>=2.2.0
Flask>=1.1.2
mtcnn>=0.1.0
Expand Down

0 comments on commit 65c47ba

Please sign in to comment.