Skip to content

Commit

Permalink
common function to get tf major version
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Jan 20, 2024
1 parent 585bdae commit 2e282db
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

warnings.filterwarnings("ignore")
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()
if tf_version == 2:
tf.get_logger().setLevel(logging.ERROR)
# -----------------------------------
Expand Down
3 changes: 1 addition & 2 deletions deepface/basemodels/ArcFace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
from deepface.commons import functions
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition
Expand All @@ -12,7 +11,7 @@
# --------------------------------
# dependency configuration

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down
3 changes: 1 addition & 2 deletions deepface/basemodels/DeepID.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os
import gdown
import tensorflow as tf
from deepface.commons import functions
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

logger = Logger(module="basemodels.DeepID")

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down
3 changes: 1 addition & 2 deletions deepface/basemodels/Facenet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
from deepface.commons import functions
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition
Expand All @@ -10,7 +9,7 @@
# --------------------------------
# dependency configuration

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down
3 changes: 1 addition & 2 deletions deepface/basemodels/FbDeepFace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import zipfile
import gdown
import tensorflow as tf
from deepface.commons import functions
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition
Expand All @@ -11,7 +10,7 @@
# --------------------------------
# dependency configuration

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model, Sequential
Expand Down
3 changes: 2 additions & 1 deletion deepface/basemodels/OpenFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

logger = Logger(module="basemodels.OpenFace")

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()
if tf_version == 1:
from keras.models import Model
from keras.layers import Conv2D, ZeroPadding2D, Input, concatenate
Expand All @@ -30,6 +30,7 @@ class OpenFace(FacialRecognition):
"""
OpenFace model class
"""

def __init__(self):
self.model = load_model()
self.model_name = "OpenFace"
Expand Down
4 changes: 1 addition & 3 deletions deepface/basemodels/VGGFace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
from deepface.commons import functions
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition
Expand All @@ -9,8 +8,7 @@

# ---------------------------------------

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])

tf_version = functions.get_tf_major_version()
if tf_version == 1:
from keras.models import Model, Sequential
from keras.layers import (
Expand Down
9 changes: 6 additions & 3 deletions deepface/commons/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
# --------------------------------------------------
# configurations of dependencies

tf_version = tf.__version__
tf_major_version = int(tf_version.split(".", maxsplit=1)[0])
tf_minor_version = int(tf_version.split(".")[1])

def get_tf_major_version() -> int:
return int(tf.__version__.split(".", maxsplit=1)[0])


tf_major_version = get_tf_major_version()

if tf_major_version == 1:
from keras.preprocessing import image
Expand Down
3 changes: 1 addition & 2 deletions deepface/extendedmodels/Age.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import gdown
import numpy as np
import tensorflow as tf
from deepface.basemodels import VGGFace
from deepface.commons import functions
from deepface.commons.logger import Logger
Expand All @@ -12,7 +11,7 @@
# ----------------------------------------
# dependency configurations

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model, Sequential
Expand Down
3 changes: 1 addition & 2 deletions deepface/extendedmodels/Emotion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
import numpy as np
import cv2
from deepface.commons import functions
Expand All @@ -13,7 +12,7 @@
# pylint: disable=line-too-long
# -------------------------------------------
# dependency configuration
tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Sequential
Expand Down
4 changes: 1 addition & 3 deletions deepface/extendedmodels/Gender.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
import numpy as np
from deepface.basemodels import VGGFace
from deepface.commons import functions
Expand All @@ -14,8 +13,7 @@
# -------------------------------------
# dependency configurations

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])

tf_version = functions.get_tf_major_version()
if tf_version == 1:
from keras.models import Model, Sequential
from keras.layers import Convolution2D, Flatten, Activation
Expand Down
3 changes: 1 addition & 2 deletions deepface/extendedmodels/Race.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import gdown
import tensorflow as tf
import numpy as np
from deepface.basemodels import VGGFace
from deepface.commons import functions
Expand All @@ -13,7 +12,7 @@
# pylint: disable=line-too-long
# --------------------------
# dependency configurations
tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()

if tf_version == 1:
from keras.models import Model, Sequential
Expand Down
5 changes: 2 additions & 3 deletions deepface/models/Demography.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Union
from abc import ABC, abstractmethod
import numpy as np
import tensorflow as tf

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
from deepface.commons import functions

tf_version = functions.get_tf_major_version()
if tf_version == 1:
from keras.models import Model
else:
Expand Down
4 changes: 2 additions & 2 deletions deepface/models/FacialRecognition.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC
from typing import Any, Union
import numpy as np
import tensorflow as tf
from deepface.commons import functions

tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
tf_version = functions.get_tf_major_version()
if tf_version == 2:
from tensorflow.keras.models import Model
else:
Expand Down

0 comments on commit 2e282db

Please sign in to comment.