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
14.38k stars 2.2k forks source link

[HELP NEEDED] High memory usage while working with celery workers #584

Closed KaushikSathvara closed 2 years ago

KaushikSathvara commented 2 years ago

I have created a task and loading a deepface model in the task method. But when it loads more celery workers it causes high memeory uses as each celery worker loading a seprate deepface model in it's context. Can we share context between those workers to load a deepface model once and predicting result on each worker.

EDIT: Please take a look at following psudo code for ref.

@app.task(...)
def celery_task(image_path):
  # Need to analyse all the available actions
  analysis = DeepFace.analyze(
                  <img_path>, actions=["age", "gender", "race", "emotion"]
              )
...further process analysis

Please note that each time above function executes it builds the model and counsume the lot of ram

serengil commented 2 years ago

this is expected behaviour. independent works will allocate memory much more. unfortunately, you cannot share the memory between them.

shafay07 commented 1 year ago

@serengil, thank you for developing Deepface. I am in a similar situation, what would be the alternative solution here to avoid high memory usage in Celery workers? @KaushikSathvara how did you end up implementing this?

KaushikSathvara commented 1 year ago

Reduced parallel worker for now @shafay07 But still finding a way to handling situation