serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
13.65k stars 2.14k forks source link

[BUG]: Unable to load pre-downloaded model weights #1290

Closed michielswaanen closed 2 months ago

michielswaanen commented 2 months ago

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

DeepFace's version

0.0.92

Python version

3.12

Operating System

Debian

Dependencies

9 229.0 absl-py==2.1.0

9 229.0 astunparse==1.6.3

9 229.0 beautifulsoup4==4.12.3

9 229.0 blinker==1.8.2

9 229.0 certifi==2024.7.4

9 229.0 charset-normalizer==3.3.2

9 229.0 click==8.1.7

9 229.0 deepface==0.0.92

9 229.0 filelock==3.15.4

9 229.0 fire==0.6.0

9 229.0 Flask==3.0.3

9 229.0 flatbuffers==24.3.25

9 229.0 gast==0.6.0

9 229.0 gdown==5.2.0

9 229.0 google-pasta==0.2.0

9 229.0 grpcio==1.65.2

9 229.0 gunicorn==22.0.0

9 229.0 h5py==3.11.0

9 229.0 idna==3.7

9 229.0 itsdangerous==2.2.0

9 229.0 Jinja2==3.1.4

9 229.0 keras==3.4.1

9 229.0 libclang==18.1.1

9 229.0 Markdown==3.6

9 229.0 markdown-it-py==3.0.0

9 229.0 MarkupSafe==2.1.5

9 229.0 mdurl==0.1.2

9 229.0 ml-dtypes==0.4.0

9 229.0 mtcnn==0.1.1

9 229.0 namex==0.0.8

9 229.0 numpy==1.26.4

9 229.0 opencv-python==4.10.0.84

9 229.0 opt-einsum==3.3.0

9 229.0 optree==0.12.1

9 229.0 packaging==24.1

9 229.0 pandas==2.2.2

9 229.0 pillow==10.4.0

9 229.0 protobuf==4.25.4

9 229.0 Pygments==2.18.0

9 229.0 PySocks==1.7.1

9 229.0 python-dateutil==2.9.0.post0

9 229.0 pytz==2024.1

9 229.0 requests==2.32.3

9 229.0 retina-face==0.0.17

9 229.0 rich==13.7.1

9 229.0 setuptools==71.1.0

9 229.0 six==1.16.0

9 229.0 soupsieve==2.5

9 229.0 tensorboard==2.17.0

9 229.0 tensorboard-data-server==0.7.2

9 229.0 tensorflow==2.17.0

9 229.0 termcolor==2.4.0

9 229.0 tf_keras==2.17.0

9 229.0 tqdm==4.66.4

9 229.0 typing_extensions==4.12.2

9 229.0 tzdata==2024.1

9 229.0 urllib3==2.2.2

9 229.0 waitress==3.0.0

9 229.0 Werkzeug==3.0.3

9 229.0 wheel==0.43.0

9 229.0 wrapt==1.16.0

Reproducible example

from retinaface import RetinaFace

RetinaFace.detect_faces("image.jpg")
FROM python:3-slim

WORKDIR /app

COPY apps/face/requirements.txt ./requirements.txt

ENV DEEPFACE_HOME /home

RUN apt-get update && \
    apt-get install ffmpeg libsm6 libxext6 curl -y && \
    pip install --no-cache-dir -r requirements.txt && \

    # Download pre-trained model
    curl -o retinaface.h5 https://github.com/serengil/deepface_models/releases/download/v1.0/retinaface.h5 && \
    mkdir -p /home/.deepface/weights/ && \
    mv retinaface.h5 /home/.deepface/weights/retinaface.h5

COPY apps/face/src ./src

CMD [ "python", "./src/index.py" ]


### Relevant Log Output

Unable to synchronously open file (file signature not found)

### Expected Result

The same behavior as if no model was pre-installed in Docker. 

### What happened instead?

When the model is called it returns this error: Unable to synchronously open file (file signature not found).
Saw some old closed issues but these didn't work

### Additional Info

_No response_
serengil commented 2 months ago

weight file is available at https://github.com/serengil/deepface_models/releases/download/v1.0/retinaface.h5

try to download it manually, paste into the repo and copy in your docker file

you most probably having this issue because of proxy or firewall. it is not an issue related to deepface. it is related to network level communication.

michielswaanen commented 2 months ago

Turns out it was my curl command that was missing the -L parameter.

curl -L -o {model_name} https://github.com/serengil/deepface_models/releases/download/v1.0/{model_name}.h5