serengil/deepface

[BUG]: <short description of the issue>

Closed this issue · 6 comments

Before You Report a Bug, Please Confirm You Have Done The Following...

  • I have updated to the latest version of the packages.
  • I have searched for both existing issues and closed issues and found none that matched my issue.

DeepFace's version

v0.0.93

Python version

3.10.12

Operating System

Ubuntu 22.04

Dependencies

absl-py 2.1.0
accelerate 0.30.1
aiohappyeyeballs 2.3.5
aiohttp 3.10.3
aiosignal 1.3.1
annotated-types 0.7.0
anthropic 0.28.1
anyio 4.4.0
asgiref 3.8.1
astunparse 1.6.3
async-timeout 4.0.3
attrs 24.2.0
azure-ai-documentintelligence 1.0.0b3
azure-ai-formrecognizer 3.3.3
azure-common 1.1.28
azure-core 1.30.2
azure-identity 1.17.1
azure-keyvault-secrets 4.8.0
backoff 2.2.1
bcrypt 4.2.0
beautifulsoup4 4.12.3
blinker 1.8.2
boto3 1.34.160
botocore 1.34.160
build 1.2.1
cachetools 5.4.0
certifi 2024.7.4
cffi 1.17.0
charset-normalizer 3.3.2
chroma-hnswlib 0.7.3
chromadb 0.5.0
click 8.1.7
coloredlogs 15.0.1
cryptography 43.0.0
dataclasses-json 0.6.7
deepface 0.0.93
Deprecated 1.2.14
dirtyjson 1.0.8
distro 1.9.0
dnspython 2.6.1
email_validator 2.2.0
et-xmlfile 1.1.0
exceptiongroup 1.2.2
fastapi 0.111.0
fastapi-cli 0.0.5
filelock 3.15.4
fire 0.6.0
Flask 3.0.3
Flask-Cors 4.0.1
flatbuffers 24.3.25
frozenlist 1.4.1
fsspec 2024.6.1
gast 0.6.0
gdown 5.2.0
google-auth 2.33.0
google-pasta 0.2.0
googleapis-common-protos 1.63.2
greenlet 3.0.3
grpcio 1.65.4
gunicorn 22.0.0
h11 0.14.0
h5py 3.11.0
httpcore 1.0.5
httptools 0.6.1
httpx 0.27.0
huggingface-hub 0.24.5
humanfriendly 10.0
idna 3.7
importlib_metadata 8.0.0
importlib_resources 6.4.0
isodate 0.6.1
itsdangerous 2.2.0
Jinja2 3.1.4
jiter 0.5.0
jmespath 1.0.1
joblib 1.4.2
jsonpatch 1.33
jsonpointer 3.0.0
jsonschema 4.23.0
jsonschema-specifications 2023.12.1
keras 3.5.0
kubernetes 30.1.0
langchain 0.2.13
langchain-community 0.2.5
langchain-core 0.2.30
langchain-openai 0.1.8
langchain-text-splitters 0.2.2
langsmith 0.1.81
libclang 18.1.1
llama-cloud 0.0.6
llama-index 0.10.67.post1
llama-index-agent-openai 0.2.7
llama-index-cli 0.1.13
llama-index-core 0.10.67
llama-index-embeddings-azure-openai 0.1.10
llama-index-embeddings-openai 0.1.10
llama-index-experimental 0.1.3
llama-index-indices-managed-llama-cloud 0.2.4
llama-index-legacy 0.9.48
llama-index-llms-anthropic 0.1.17
llama-index-llms-azure-openai 0.1.10
llama-index-llms-bedrock 0.1.7
llama-index-llms-openai 0.1.26
llama-index-multi-modal-llms-openai 0.1.9
llama-index-program-openai 0.1.6
llama-index-question-gen-openai 0.1.3
llama-index-readers-file 0.1.33
llama-index-readers-llama-parse 0.1.6
llama-parse 0.4.9
Markdown 3.6
markdown-it-py 3.0.0
MarkupSafe 2.1.5
marshmallow 3.21.3
mdurl 0.1.2
ml-dtypes 0.4.0
mmh3 4.1.0
monotonic 1.6
mpmath 1.3.0
msal 1.30.0
msal-extensions 1.2.0
msrest 0.7.1
mtcnn 0.1.1
multidict 6.0.5
mypy-extensions 1.0.0
namex 0.0.8
nest-asyncio 1.6.0
networkx 3.3
nltk 3.8.2
numpy 1.26.4
nvidia-cublas-cu12 12.1.3.1
nvidia-cuda-cupti-cu12 12.1.105
nvidia-cuda-nvrtc-cu12 12.1.105
nvidia-cuda-runtime-cu12 12.1.105
nvidia-cudnn-cu12 8.9.2.26
nvidia-cufft-cu12 11.0.2.54
nvidia-curand-cu12 10.3.2.106
nvidia-cusolver-cu12 11.4.5.107
nvidia-cusparse-cu12 12.1.0.106
nvidia-nccl-cu12 2.20.5
nvidia-nvjitlink-cu12 12.6.20
nvidia-nvtx-cu12 12.1.105
oauthlib 3.2.2
onnxruntime 1.18.1
openai 1.40.6
opencv-python 4.10.0.84
openpyxl 3.1.4
opentelemetry-api 1.26.0
opentelemetry-exporter-otlp-proto-common 1.26.0
opentelemetry-exporter-otlp-proto-grpc 1.26.0
opentelemetry-instrumentation 0.47b0
opentelemetry-instrumentation-asgi 0.47b0
opentelemetry-instrumentation-fastapi 0.47b0
opentelemetry-proto 1.26.0
opentelemetry-sdk 1.26.0
opentelemetry-semantic-conventions 0.47b0
opentelemetry-util-http 0.47b0
opt-einsum 3.3.0
optree 0.12.1
orjson 3.10.7
overrides 7.7.0
packaging 24.1
pandas 2.2.2
pillow 10.4.0
pip 23.2.1
portalocker 2.10.1
posthog 3.5.0
protobuf 4.25.4
psutil 6.0.0
psycopg2-binary 2.9.9
pyasn1 0.6.0
pyasn1_modules 0.4.0
pycparser 2.22
pydantic 2.8.2
pydantic_core 2.20.1
Pygments 2.18.0
PyJWT 2.9.0
PyMySQL 1.1.1
pypdf 4.3.1
PyPika 0.48.9
pyproject_hooks 1.1.0
pyproject-toml 0.0.10
PySocks 1.7.1
pysqlite3-binary 0.5.3
python-dateutil 2.9.0.post0
python-dotenv 1.0.1
python-multipart 0.0.9
pytz 2024.1
PyYAML 6.0.2
referencing 0.35.1
regex 2024.7.24
requests 2.32.3
requests-oauthlib 2.0.0
retina-face 0.0.17
rich 13.7.1
rpds-py 0.20.0
rsa 4.9
s3transfer 0.10.2
safetensors 0.4.4
setuptools 68.2.0
shellingham 1.5.4
six 1.16.0
sniffio 1.3.1
soupsieve 2.6
SQLAlchemy 2.0.31
starlette 0.37.2
striprtf 0.0.26
sympy 1.13.2
tenacity 8.5.0
tensorboard 2.17.0
tensorboard-data-server 0.7.2
tensorflow 2.17.0
tensorflow-io-gcs-filesystem 0.37.1
termcolor 2.4.0
tf_keras 2.17.0
tiktoken 0.7.0
tokenizers 0.19.1
toml 0.10.2
tomli 2.0.1
torch 2.3.0
tqdm 4.66.5
transformers 4.41.2
triton 2.3.0
typer 0.12.3
typing_extensions 4.12.2
typing-inspect 0.9.0
tzdata 2024.1
ujson 5.10.0
urllib3 2.2.2
uvicorn 0.30.1
uvloop 0.19.0
watchfiles 0.23.0
websocket-client 1.8.0
websockets 12.0
Werkzeug 3.0.3
wheel 0.41.2
wrapt 1.16.0
yarl 1.9.4
zipp 3.20.0

Reproducible example

from deepface import DeepFace

def verify_face(image1, image2):
    verification = DeepFace.verify(image1, image2, model_name="Facenet512")
    return verification.get("distance")

Relevant Log Output

No response

Expected Result

Package should work as expected...
It was working fine in another venv with exact same dependency set.

What happened instead?

Getting an error while loading the model

Additional Info

No response

ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in call
return await self.app(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
await super().call(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in call
raise exc
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
await self.app(scope, receive, _send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/routing.py", line 756, in call
await self.middleware_stack(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app
raw_response = await run_endpoint_function(
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
return await dependant.call(**values)
File "/home/meher/ai_api_ekyc/main.py", line 241, in verify_docs
print(face_ver.verify_face("detected_faces/" + photo_file.filename, "detected_faces/" + document_file.filename))
File "/home/meher/ai_api_ekyc/face_ver.py", line 5, in verify_face
verification = DeepFace.verify(image1, image2, model_name="Facenet512")
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/deepface/DeepFace.py", line 150, in verify
return verification.verify(
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/deepface/modules/verification.py", line 103, in verify
model: FacialRecognition = modeling.build_model(
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/deepface/modules/modeling.py", line 96, in build_model
cached_models[task][model_name] = model()
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/deepface/models/facial_recognition/Facenet.py", line 64, in init
self.model = load_facenet512d_model()
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/deepface/models/facial_recognition/Facenet.py", line 1709, in load_facenet512d_model
model.load_weights(output)
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/tf_keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/meher/ai_api_ekyc/ekyc/lib/python3.10/site-packages/tf_keras/src/backend.py", line 4361, in _assign_value_to_variable
variable.assign(value)
ValueError: object array method not producing an array

This is the error I am getting

it is getting error while loading the weights, most probably weight file was broken. delete it and copy the weight to ~/.deepface/weights manually if the issue appears again.

model.load_weights(output)

Yes I have already done that twice. Still the issue persists

The same error is coming up for every single model. So i do not think the model files are the problem

Load weights is a keras command. Your tf dependency must have an issue instead of deepface itself.

model.load_weights(output)

try to downgrade tf to a lower version

e.g. 2.9.0