From 46174b90270de9d366dfb94852486814e2cf2ea0 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sun, 31 Mar 2024 13:25:47 +0100 Subject: [PATCH 1/2] make retinaface compatible with tf2.16 and later --- retinaface/RetinaFace.py | 8 ++++++++ retinaface/commons/package_utils.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 retinaface/commons/package_utils.py diff --git a/retinaface/RetinaFace.py b/retinaface/RetinaFace.py index cb72180..cc82831 100644 --- a/retinaface/RetinaFace.py +++ b/retinaface/RetinaFace.py @@ -3,6 +3,10 @@ import logging from typing import Union, Any, Optional, Dict +# this has to be set before importing tf +os.environ["TF_USE_LEGACY_KERAS"] = "1" + +# pylint: disable=wrong-import-position import numpy as np import tensorflow as tf @@ -10,6 +14,10 @@ from retinaface.model import retinaface_model from retinaface.commons import preprocess, postprocess from retinaface.commons.logger import Logger +from retinaface.commons import package_utils + +# users should install tf_keras package if they are using tf 2.16 or later versions +package_utils.validate_for_keras3() logger = Logger(module="retinaface/RetinaFace.py") diff --git a/retinaface/commons/package_utils.py b/retinaface/commons/package_utils.py new file mode 100644 index 0000000..ea34197 --- /dev/null +++ b/retinaface/commons/package_utils.py @@ -0,0 +1,28 @@ +# 3rd party dependencies +import tensorflow as tf + +# project dependencies +from retinaface.commons.logger import Logger + +logger = Logger(module="retinaface/commons/package_utils.py") + + +def validate_for_keras3(): + tf_major = int(tf.__version__.split(".", maxsplit=1)[0]) + tf_minor = int(tf.__version__.split(".", maxsplit=-1)[1]) + + # tf_keras is a must dependency after tf 2.16 + if tf_major == 1 or (tf_major == 2 and tf_minor < 16): + return + + try: + import tf_keras + + logger.debug(f"tf_keras is already available - {tf_keras.__version__}") + except ImportError as err: + # you may consider to install that package here + raise ValueError( + f"You have tensorflow {tf.__version__} and this requires " + "tf-keras package. Please run `pip install tf-keras` " + "or downgrade your tensorflow." + ) from err From 175fdb8630e9b658ada131aecf91078526a23f41 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sun, 31 Mar 2024 13:29:28 +0100 Subject: [PATCH 2/2] new release version --- package_info.json | 2 +- retinaface/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package_info.json b/package_info.json index 92ca348..73786c1 100644 --- a/package_info.json +++ b/package_info.json @@ -1,3 +1,3 @@ { - "version": "0.0.15" + "version": "0.0.16" } \ No newline at end of file diff --git a/retinaface/__init__.py b/retinaface/__init__.py index 6561790..d62d967 100644 --- a/retinaface/__init__.py +++ b/retinaface/__init__.py @@ -1 +1 @@ -__version__ = "0.0.15" +__version__ = "0.0.16"