cc1234 commited on
Commit
9e1ec94
1 Parent(s): 44c0908

initial commit

Browse files
.deepface/weights/facenet512_weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f76b5117a9ca574d536af8199e6720089eb4ad3dc7e93534496d88265de864f
3
+ size 94955648
.deepface/weights/retinaface.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecb2393a89da3dd3d6796ad86660e298f62a0c8ae7578d92eb6af14e0bb93adf
3
+ size 118667368
.gitattributes CHANGED
@@ -31,3 +31,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
31
  *.zip filter=lfs diff=lfs merge=lfs -text
32
  *.zst filter=lfs diff=lfs merge=lfs -text
33
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
31
  *.zip filter=lfs diff=lfs merge=lfs -text
32
  *.zst filter=lfs diff=lfs merge=lfs -text
33
  *tfevents* filter=lfs diff=lfs merge=lfs -text
34
+ *.db filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ flagged
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+
4
+ print(os.path.dirname(__file__))
5
+ os.environ["DEEPFACE_HOME"] = os.path.dirname(__file__)
6
+
7
+ import pyzipper
8
+ import numpy as np
9
+ import gradio as gr
10
+ from annoy import AnnoyIndex
11
+ from deepface.commons import functions
12
+ from deepface.basemodels import Facenet512
13
+
14
+
15
+ # load the face model
16
+ model = Facenet512.loadModel()
17
+
18
+ input_shape_x, input_shape_y = functions.find_input_shape(model)
19
+
20
+ index = AnnoyIndex(512, "euclidean")
21
+ index.load(f"face.db")
22
+
23
+ ANNOY_INDEX = json.load(open(f"face.json"))
24
+
25
+ with pyzipper.AESZipFile('persons.zip') as zf:
26
+ zf.setpassword(b"4321ecafhsats"[::-1])
27
+ PERFORMER_DB = json.loads(zf.read('performers.json'))
28
+
29
+
30
+ def predict(image, threshold=20.0, results=3):
31
+ image_array = np.array(image)
32
+
33
+ img = functions.preprocess_face(
34
+ img=image_array,
35
+ target_size=(input_shape_x, input_shape_y),
36
+ enforce_detection=True,
37
+ detector_backend="retinaface",
38
+ align=True,
39
+ )
40
+
41
+ img = functions.normalize_input(img, normalization="Facenet2018")
42
+ face = model.predict(img)[0].tolist()
43
+ ids, distances = index.get_nns_by_vector(
44
+ face, 50, search_k=10000, include_distances=True
45
+ )
46
+
47
+ persons = {}
48
+ for p, distance in zip(ids, distances):
49
+ id = ANNOY_INDEX[p]
50
+ if id in persons:
51
+ persons[id]["hits"] += 1
52
+ persons[id]["distance"] -= 0.5
53
+ continue
54
+
55
+ persons[id] = {
56
+ "id": id,
57
+ "distance": round(distance, 2),
58
+ "hits": 1,
59
+ }
60
+
61
+ if id in PERFORMER_DB:
62
+ persons[id].update(PERFORMER_DB.get(id))
63
+
64
+ persons = sorted(persons.values(), key=lambda x: x["distance"])
65
+ persons = [p for p in persons if p["distance"] < threshold]
66
+ return persons[:results]
67
+
68
+
69
+ gr.Interface(
70
+ fn=predict,
71
+ inputs=[
72
+ gr.components.Image(),
73
+ gr.components.Slider(label="threshold",minimum=0.0, maximum=30.0, value=20.0),
74
+ gr.components.Slider(label="results", minimum=0, maximum=10, value=3),
75
+ ],
76
+ outputs=gr.outputs.JSON(label=""),
77
+ title="Who is in the photo?",
78
+ description="Upload an image of a person and we'll tell you who it is.",
79
+ ).launch(enable_queue=True)
face.db ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e73f162347245f8d4267ac2a4f2788b77d0910185b505152fceca0320a840b84
3
+ size 399631680
face.json ADDED
The diff for this file is too large to render. See raw diff
 
persons.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2af1307a506a612e7d61bdaad3e40c6cb348c1420166628044309bc55d4376fa
3
+ size 2530170
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ annoy==1.17.1
2
+ deepface==0.0.75
3
+ pyzipper
4
+ gradio