Skip to content

Commit f195dbf

Browse files
authored
Merge pull request #999 from serengil/feat-task-0202-improvements
open issues
2 parents 64d3371 + 8497682 commit f195dbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+332
-230
lines changed

CITATION.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Cite DeepFace Papers
2+
3+
Please cite deepface in your publications if it helps your research. Here are its BibTex entries:
4+
5+
### Facial Recognition
6+
7+
If you use deepface in your research for facial recogntion purposes, please cite the this publication.
8+
9+
```BibTeX
10+
@inproceedings{serengil2020lightface,
11+
title = {LightFace: A Hybrid Deep Face Recognition Framework},
12+
author = {Serengil, Sefik Ilkin and Ozpinar, Alper},
13+
booktitle = {2020 Innovations in Intelligent Systems and Applications Conference (ASYU)},
14+
pages = {23-27},
15+
year = {2020},
16+
doi = {10.1109/ASYU50717.2020.9259802},
17+
url = {https://doi.org/10.1109/ASYU50717.2020.9259802},
18+
organization = {IEEE}
19+
}
20+
```
21+
22+
### Facial Attribute Analysis
23+
24+
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.
25+
26+
```BibTeX
27+
@inproceedings{serengil2021lightface,
28+
title = {HyperExtended LightFace: A Facial Attribute Analysis Framework},
29+
author = {Serengil, Sefik Ilkin and Ozpinar, Alper},
30+
booktitle = {2021 International Conference on Engineering and Emerging Technologies (ICEET)},
31+
pages = {1-4},
32+
year = {2021},
33+
doi = {10.1109/ICEET53442.2021.9659697},
34+
url = {https://doi.org/10.1109/ICEET53442.2021.9659697},
35+
organization = {IEEE}
36+
}
37+
```
38+
39+
### Repositories
40+
41+
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).

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ RUN apt-get install ffmpeg libsm6 libxext6 -y
1919
# -----------------------------------
2020
# Copy required files from repo into image
2121
COPY ./deepface /app/deepface
22-
COPY ./api/app.py /app/
23-
COPY ./api/api.py /app/
24-
COPY ./api/routes.py /app/
25-
COPY ./api/service.py /app/
22+
COPY ./api/src/app.py /app/
23+
COPY ./api/src/api.py /app/
24+
COPY ./api/src/routes.py /app/
25+
COPY ./api/src/service.py /app/
2626
COPY ./requirements.txt /app/
2727
COPY ./setup.py /app/
2828
COPY ./README.md /app/

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ cd scripts
289289

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

292-
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.
292+
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.
293293

294294
**Dockerized Service**
295295

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

333333
## Citation
334334

335-
Please cite deepface in your publications if it helps your research. Here are its BibTex entries:
335+
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:
336336

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

339339
```BibTeX
340340
@inproceedings{serengil2020lightface,
@@ -349,7 +349,7 @@ If you use deepface for facial recogntion purposes, please cite the this publica
349349
}
350350
```
351351

352-
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.
352+
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.
353353

354354
```BibTeX
355355
@inproceedings{serengil2021lightface,

api/api.py api/src/api.py

File renamed without changes.

api/app.py api/src/app.py

File renamed without changes.

api/routes.py api/src/routes.py

File renamed without changes.

api/service.py api/src/service.py

File renamed without changes.

deepface/DeepFace.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import tensorflow as tf
1111

1212
# package dependencies
13-
from deepface.commons import functions
13+
from deepface.commons import package_utils, folder_utils
1414
from deepface.commons.logger import Logger
1515
from deepface.modules import (
1616
modeling,
@@ -24,17 +24,21 @@
2424

2525
logger = Logger(module="DeepFace")
2626

27+
# current package version of deepface
28+
__version__ = package_utils.find_package_version()
29+
2730
# -----------------------------------
2831
# configurations for dependencies
2932

3033
warnings.filterwarnings("ignore")
3134
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
32-
tf_version = functions.get_tf_major_version()
35+
tf_version = package_utils.get_tf_major_version()
3336
if tf_version == 2:
3437
tf.get_logger().setLevel(logging.ERROR)
3538
# -----------------------------------
3639

37-
functions.initialize_folder()
40+
# create required folders if necessary to store model weights
41+
folder_utils.initialize_folder()
3842

3943

4044
def build_model(model_name: str) -> Any:
@@ -511,7 +515,7 @@ def detectFace(
511515
align (bool): Flag to enable face alignment (default is True).
512516
513517
Returns:
514-
img (np.ndarray): detected (and aligned) facial area image as numpy array
518+
img (np.ndarray): detected (and aligned) facial area image as numpy array
515519
"""
516520
logger.warn("Function detectFace is deprecated. Use extract_faces instead.")
517521
face_objs = extract_faces(

deepface/basemodels/ArcFace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import gdown
44
import numpy as np
5-
from deepface.commons import functions
5+
from deepface.commons import package_utils, folder_utils
66
from deepface.commons.logger import Logger
77
from deepface.models.FacialRecognition import FacialRecognition
88

@@ -13,7 +13,7 @@
1313
# --------------------------------
1414
# dependency configuration
1515

16-
tf_version = functions.get_tf_major_version()
16+
tf_version = package_utils.get_tf_major_version()
1717

1818
if tf_version == 1:
1919
from keras.models import Model
@@ -94,7 +94,7 @@ def load_model(
9494
# ---------------------------------------
9595
# check the availability of pre-trained weights
9696

97-
home = functions.get_deepface_home()
97+
home = folder_utils.get_deepface_home()
9898

9999
file_name = "arcface_weights.h5"
100100
output = home + "/.deepface/weights/" + file_name

deepface/basemodels/DeepID.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import os
33
import gdown
44
import numpy as np
5-
from deepface.commons import functions
5+
from deepface.commons import package_utils, folder_utils
66
from deepface.commons.logger import Logger
77
from deepface.models.FacialRecognition import FacialRecognition
88

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

11-
tf_version = functions.get_tf_major_version()
11+
tf_version = package_utils.get_tf_major_version()
1212

1313
if tf_version == 1:
1414
from keras.models import Model
@@ -100,7 +100,7 @@ def load_model(
100100

101101
# ---------------------------------
102102

103-
home = functions.get_deepface_home()
103+
home = folder_utils.get_deepface_home()
104104

105105
if os.path.isfile(home + "/.deepface/weights/deepid_keras_weights.h5") != True:
106106
logger.info("deepid_keras_weights.h5 will be downloaded...")

deepface/basemodels/Dlib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import bz2
44
import gdown
55
import numpy as np
6-
from deepface.commons import functions
6+
from deepface.commons import folder_utils
77
from deepface.commons.logger import Logger
88
from deepface.models.FacialRecognition import FacialRecognition
99

@@ -68,7 +68,7 @@ def __init__(self):
6868

6969
# ---------------------
7070

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

7474
# ---------------------

deepface/basemodels/Facenet.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import gdown
44
import numpy as np
5-
from deepface.commons import functions
5+
from deepface.commons import package_utils, folder_utils
66
from deepface.commons.logger import Logger
77
from deepface.models.FacialRecognition import FacialRecognition
88

@@ -11,7 +11,7 @@
1111
# --------------------------------
1212
# dependency configuration
1313

14-
tf_version = functions.get_tf_major_version()
14+
tf_version = package_utils.get_tf_major_version()
1515

1616
if tf_version == 1:
1717
from keras.models import Model
@@ -1689,7 +1689,7 @@ def load_facenet128d_model(
16891689

16901690
# -----------------------------------
16911691

1692-
home = functions.get_deepface_home()
1692+
home = folder_utils.get_deepface_home()
16931693

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

17201720
# -------------------------
17211721

1722-
home = functions.get_deepface_home()
1722+
home = folder_utils.get_deepface_home()
17231723

17241724
if os.path.isfile(home + "/.deepface/weights/facenet512_weights.h5") != True:
17251725
logger.info("facenet512_weights.h5 will be downloaded...")

deepface/basemodels/FbDeepFace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import zipfile
44
import gdown
55
import numpy as np
6-
from deepface.commons import functions
6+
from deepface.commons import package_utils, folder_utils
77
from deepface.commons.logger import Logger
88
from deepface.models.FacialRecognition import FacialRecognition
99

@@ -12,7 +12,7 @@
1212
# --------------------------------
1313
# dependency configuration
1414

15-
tf_version = functions.get_tf_major_version()
15+
tf_version = package_utils.get_tf_major_version()
1616

1717
if tf_version == 1:
1818
from keras.models import Model, Sequential
@@ -84,7 +84,7 @@ def load_model(
8484

8585
# ---------------------------------
8686

87-
home = functions.get_deepface_home()
87+
home = folder_utils.get_deepface_home()
8888

8989
if os.path.isfile(home + "/.deepface/weights/VGGFace2_DeepFace_weights_val-0.9034.h5") != True:
9090
logger.info("VGGFace2_DeepFace_weights_val-0.9034.h5 will be downloaded...")

deepface/basemodels/OpenFace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import gdown
44
import tensorflow as tf
55
import numpy as np
6-
from deepface.commons import functions
6+
from deepface.commons import package_utils, folder_utils
77
from deepface.commons.logger import Logger
88
from deepface.models.FacialRecognition import FacialRecognition
99

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

12-
tf_version = functions.get_tf_major_version()
12+
tf_version = package_utils.get_tf_major_version()
1313
if tf_version == 1:
1414
from keras.models import Model
1515
from keras.layers import Conv2D, ZeroPadding2D, Input, concatenate
@@ -394,7 +394,7 @@ def load_model(
394394

395395
# -----------------------------------
396396

397-
home = functions.get_deepface_home()
397+
home = folder_utils.get_deepface_home()
398398

399399
if os.path.isfile(home + "/.deepface/weights/openface_weights.h5") != True:
400400
logger.info("openface_weights.h5 will be downloaded...")

deepface/basemodels/SFace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import cv2 as cv
66
import gdown
77

8-
from deepface.commons import functions
8+
from deepface.commons import folder_utils
99
from deepface.commons.logger import Logger
1010
from deepface.models.FacialRecognition import FacialRecognition
1111

@@ -50,7 +50,7 @@ def load_model(
5050
Construct SFace model, download its weights and load
5151
"""
5252

53-
home = functions.get_deepface_home()
53+
home = folder_utils.get_deepface_home()
5454

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

deepface/basemodels/VGGFace.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import os
33
import gdown
44
import numpy as np
5-
from deepface.commons import functions, distance
5+
from deepface.commons import package_utils, folder_utils
6+
from deepface.modules import verification
67
from deepface.models.FacialRecognition import FacialRecognition
78
from deepface.commons.logger import Logger
89

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

1112
# ---------------------------------------
1213

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

6566

@@ -128,7 +129,7 @@ def load_model(
128129

129130
model = base_model()
130131

131-
home = functions.get_deepface_home()
132+
home = folder_utils.get_deepface_home()
132133
output = home + "/.deepface/weights/vgg_face_weights.h5"
133134

134135
if os.path.isfile(output) != True:

deepface/commons/constant.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4+
ROOT_DIR = os.path.dirname(SRC_DIR)

0 commit comments

Comments
 (0)