Skip to content

Commit

Permalink
Merge pull request #999 from serengil/feat-task-0202-improvements
Browse files Browse the repository at this point in the history
open issues
  • Loading branch information
serengil authored Feb 2, 2024
2 parents 64d3371 + 8497682 commit f195dbf
Show file tree
Hide file tree
Showing 42 changed files with 332 additions and 230 deletions.
41 changes: 41 additions & 0 deletions CITATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Cite DeepFace Papers

Please cite deepface in your publications if it helps your research. Here are its BibTex entries:

### Facial Recognition

If you use deepface in your research for facial recogntion purposes, please cite the this publication.

```BibTeX
@inproceedings{serengil2020lightface,
title = {LightFace: A Hybrid Deep Face Recognition Framework},
author = {Serengil, Sefik Ilkin and Ozpinar, Alper},
booktitle = {2020 Innovations in Intelligent Systems and Applications Conference (ASYU)},
pages = {23-27},
year = {2020},
doi = {10.1109/ASYU50717.2020.9259802},
url = {https://doi.org/10.1109/ASYU50717.2020.9259802},
organization = {IEEE}
}
```

### Facial Attribute Analysis

If you use deepface in your research for facial attribute analysis purposes such as age, gender, emotion or ethnicity prediction or face detection purposes, please cite the this publication.

```BibTeX
@inproceedings{serengil2021lightface,
title = {HyperExtended LightFace: A Facial Attribute Analysis Framework},
author = {Serengil, Sefik Ilkin and Ozpinar, Alper},
booktitle = {2021 International Conference on Engineering and Emerging Technologies (ICEET)},
pages = {1-4},
year = {2021},
doi = {10.1109/ICEET53442.2021.9659697},
url = {https://doi.org/10.1109/ICEET53442.2021.9659697},
organization = {IEEE}
}
```

### Repositories

Also, if you use deepface in your GitHub projects, please add `deepface` in the `requirements.txt`. Thereafter, your project will be listed in its [dependency graph](https://github.com/serengil/deepface/network/dependents).
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ RUN apt-get install ffmpeg libsm6 libxext6 -y
# -----------------------------------
# Copy required files from repo into image
COPY ./deepface /app/deepface
COPY ./api/app.py /app/
COPY ./api/api.py /app/
COPY ./api/routes.py /app/
COPY ./api/service.py /app/
COPY ./api/src/app.py /app/
COPY ./api/src/api.py /app/
COPY ./api/src/routes.py /app/
COPY ./api/src/service.py /app/
COPY ./requirements.txt /app/
COPY ./setup.py /app/
COPY ./README.md /app/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ cd scripts

<p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/master/icon/deepface-api.jpg" width="90%" height="90%"></p>

Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Default service endpoints will be `http://localhost:5000/verify` for face recognition, `http://localhost:5000/analyze` for facial attribute analysis, and `http://localhost:5000/represent` for vector representation. You can pass input images as exact image paths on your environment, base64 encoded strings or images on web. [Here](https://github.com/serengil/deepface/tree/master/api), you can find a postman project to find out how these methods should be called.
Face recognition, facial attribute analysis and vector representation functions are covered in the API. You are expected to call these functions as http post methods. Default service endpoints will be `http://localhost:5000/verify` for face recognition, `http://localhost:5000/analyze` for facial attribute analysis, and `http://localhost:5000/represent` for vector representation. You can pass input images as exact image paths on your environment, base64 encoded strings or images on web. [Here](https://github.com/serengil/deepface/tree/master/api/postman), you can find a postman project to find out how these methods should be called.

**Dockerized Service**

Expand Down Expand Up @@ -332,9 +332,9 @@ You can also support this work on [Patreon](https://www.patreon.com/serengil?rep

## Citation

Please cite deepface in your publications if it helps your research. Here are its BibTex entries:
Please cite deepface in your publications if it helps your research - see [`CITATIONS`](https://github.com/serengil/deepface/blob/master/CITATIONS.md) for more details. Here are its BibTex entries:

If you use deepface for facial recogntion purposes, please cite the this publication.
If you use deepface in your research for facial recogntion purposes, please cite this publication.

```BibTeX
@inproceedings{serengil2020lightface,
Expand All @@ -349,7 +349,7 @@ If you use deepface for facial recogntion purposes, please cite the this publica
}
```

If you use deepface for facial attribute analysis purposes such as age, gender, emotion or ethnicity prediction or face detection purposes, please cite the this publication.
If you use deepface in your research for facial attribute analysis purposes such as age, gender, emotion or ethnicity prediction or face detection purposes, please cite this publication.

```BibTeX
@inproceedings{serengil2021lightface,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 8 additions & 4 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import tensorflow as tf

# package dependencies
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.modules import (
modeling,
Expand All @@ -24,17 +24,21 @@

logger = Logger(module="DeepFace")

# current package version of deepface
__version__ = package_utils.find_package_version()

# -----------------------------------
# configurations for dependencies

warnings.filterwarnings("ignore")
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()
if tf_version == 2:
tf.get_logger().setLevel(logging.ERROR)
# -----------------------------------

functions.initialize_folder()
# create required folders if necessary to store model weights
folder_utils.initialize_folder()


def build_model(model_name: str) -> Any:
Expand Down Expand Up @@ -511,7 +515,7 @@ def detectFace(
align (bool): Flag to enable face alignment (default is True).
Returns:
img (np.ndarray): detected (and aligned) facial area image as numpy array
img (np.ndarray): detected (and aligned) facial area image as numpy array
"""
logger.warn("Function detectFace is deprecated. Use extract_faces instead.")
face_objs = extract_faces(
Expand Down
6 changes: 3 additions & 3 deletions deepface/basemodels/ArcFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import gdown
import numpy as np
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

Expand All @@ -13,7 +13,7 @@
# --------------------------------
# dependency configuration

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down Expand Up @@ -94,7 +94,7 @@ def load_model(
# ---------------------------------------
# check the availability of pre-trained weights

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

file_name = "arcface_weights.h5"
output = home + "/.deepface/weights/" + file_name
Expand Down
6 changes: 3 additions & 3 deletions deepface/basemodels/DeepID.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import os
import gdown
import numpy as np
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

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

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down Expand Up @@ -100,7 +100,7 @@ def load_model(

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

if os.path.isfile(home + "/.deepface/weights/deepid_keras_weights.h5") != True:
logger.info("deepid_keras_weights.h5 will be downloaded...")
Expand Down
4 changes: 2 additions & 2 deletions deepface/basemodels/Dlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bz2
import gdown
import numpy as np
from deepface.commons import functions
from deepface.commons import folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self):

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()
weight_file = home + "/.deepface/weights/dlib_face_recognition_resnet_model_v1.dat"

# ---------------------
Expand Down
8 changes: 4 additions & 4 deletions deepface/basemodels/Facenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import gdown
import numpy as np
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

Expand All @@ -11,7 +11,7 @@
# --------------------------------
# dependency configuration

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()

if tf_version == 1:
from keras.models import Model
Expand Down Expand Up @@ -1689,7 +1689,7 @@ def load_facenet128d_model(

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

if os.path.isfile(home + "/.deepface/weights/facenet_weights.h5") != True:
logger.info("facenet_weights.h5 will be downloaded...")
Expand Down Expand Up @@ -1719,7 +1719,7 @@ def load_facenet512d_model(

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

if os.path.isfile(home + "/.deepface/weights/facenet512_weights.h5") != True:
logger.info("facenet512_weights.h5 will be downloaded...")
Expand Down
6 changes: 3 additions & 3 deletions deepface/basemodels/FbDeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import zipfile
import gdown
import numpy as np
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

Expand All @@ -12,7 +12,7 @@
# --------------------------------
# dependency configuration

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()

if tf_version == 1:
from keras.models import Model, Sequential
Expand Down Expand Up @@ -84,7 +84,7 @@ def load_model(

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

if os.path.isfile(home + "/.deepface/weights/VGGFace2_DeepFace_weights_val-0.9034.h5") != True:
logger.info("VGGFace2_DeepFace_weights_val-0.9034.h5 will be downloaded...")
Expand Down
6 changes: 3 additions & 3 deletions deepface/basemodels/OpenFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import gdown
import tensorflow as tf
import numpy as np
from deepface.commons import functions
from deepface.commons import package_utils, folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

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

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()
if tf_version == 1:
from keras.models import Model
from keras.layers import Conv2D, ZeroPadding2D, Input, concatenate
Expand Down Expand Up @@ -394,7 +394,7 @@ def load_model(

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

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

if os.path.isfile(home + "/.deepface/weights/openface_weights.h5") != True:
logger.info("openface_weights.h5 will be downloaded...")
Expand Down
4 changes: 2 additions & 2 deletions deepface/basemodels/SFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cv2 as cv
import gdown

from deepface.commons import functions
from deepface.commons import folder_utils
from deepface.commons.logger import Logger
from deepface.models.FacialRecognition import FacialRecognition

Expand Down Expand Up @@ -50,7 +50,7 @@ def load_model(
Construct SFace model, download its weights and load
"""

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()

file_name = home + "/.deepface/weights/face_recognition_sface_2021dec.onnx"

Expand Down
9 changes: 5 additions & 4 deletions deepface/basemodels/VGGFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import os
import gdown
import numpy as np
from deepface.commons import functions, distance
from deepface.commons import package_utils, folder_utils
from deepface.modules import verification
from deepface.models.FacialRecognition import FacialRecognition
from deepface.commons.logger import Logger

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

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

tf_version = functions.get_tf_major_version()
tf_version = package_utils.get_tf_major_version()
if tf_version == 1:
from keras.models import Model, Sequential
from keras.layers import (
Expand Down Expand Up @@ -59,7 +60,7 @@ def find_embeddings(self, img: np.ndarray) -> List[float]:
# having normalization layer in descriptor troubles for some gpu users (e.g. issue 957, 966)
# instead we are now calculating it with traditional way not with keras backend
embedding = self.model(img, training=False).numpy()[0].tolist()
embedding = distance.l2_normalize(embedding)
embedding = verification.l2_normalize(embedding)
return embedding.tolist()


Expand Down Expand Up @@ -128,7 +129,7 @@ def load_model(

model = base_model()

home = functions.get_deepface_home()
home = folder_utils.get_deepface_home()
output = home + "/.deepface/weights/vgg_face_weights.h5"

if os.path.isfile(output) != True:
Expand Down
4 changes: 4 additions & 0 deletions deepface/commons/constant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT_DIR = os.path.dirname(SRC_DIR)
Loading

0 comments on commit f195dbf

Please sign in to comment.