From 183dfb1717e6e8887488dda49eb3b0bf6950b7cb Mon Sep 17 00:00:00 2001 From: Inga Ulusoy Date: Wed, 10 Sep 2025 08:39:31 +0200 Subject: [PATCH] maintain+bug: fix python version due to deepface, fix deepface memory leak --- .github/workflows/ci.yml | 2 +- ammico/faces.py | 7 +++++++ pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c7186a..d6b2ddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: [3.9, 3.10, 3.11, 3.12, 3.13] + python-version: ['3.9', '3.11'] steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/ammico/faces.py b/ammico/faces.py index d731c2a..bdb639f 100644 --- a/ammico/faces.py +++ b/ammico/faces.py @@ -6,12 +6,17 @@ import pathlib from tensorflow.keras.models import load_model from tensorflow.keras.applications.mobilenet_v2 import preprocess_input from tensorflow.keras.preprocessing.image import img_to_array +import keras.backend as K from deepface import DeepFace from retinaface import RetinaFace from ammico.utils import DownloadResource, AnalysisMethod DEEPFACE_PATH = ".deepface" +# alternative solution to the memory leaks +# cfg = K.tf.compat.v1.ConfigProto() +# cfg.gpu_options.allow_growth = True +# K.set_session(K.tf.compat.v1.Session(config=cfg)) def deepface_symlink_processor(name): @@ -305,6 +310,8 @@ class EmotionDetector(AnalysisMethod): for i, face in enumerate(faces[:3]): result[f"person{i+1}"] = self.analyze_single_face(face) self.clean_subdict(result) + # release memory + K.clear_session() return self.subdict def clean_subdict(self, result: dict) -> dict: diff --git a/pyproject.toml b/pyproject.toml index 08a59b3..4cad313 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ maintainers = [ { name = "Inga Ulusoy", email = "ssc@iwr.uni-heidelberg.de" }, { name = "Dmitrii Kapitan", email = "ssc@iwr.uni-heidelberg.de" }, ] -requires-python = ">=3.9" +requires-python = ">=3.9, <3.12" license = { text = "MIT" } classifiers = [ "Programming Language :: Python :: 3",