Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,37 +24,42 @@ for img in source_imgs:
|
|
24 |
try:
|
25 |
faces, id = extract_faces(detector, img)
|
26 |
source_faces.append(faces[id])
|
27 |
-
source_faces.append(Image.open(img))
|
28 |
except Exception as e:
|
29 |
print(f"Skipping {img}, {e}")
|
30 |
|
31 |
source_embeddings = get_embeddings(model, source_faces)
|
32 |
|
33 |
-
def find_names(image):
|
34 |
imgs, _ = extract_faces(detector, image)
|
35 |
for i, face in enumerate(imgs):
|
36 |
-
|
|
|
37 |
del imgs[i]
|
38 |
|
39 |
embeds = get_embeddings(model, imgs)
|
|
|
40 |
d = np.zeros((len(source_embeddings), len(embeds)))
|
41 |
for i, s in enumerate(source_embeddings):
|
42 |
for j, t in enumerate(embeds):
|
43 |
d[i][j] = findCosineDistance(s, t)
|
44 |
ids = np.argmin(d, axis = 0)
|
45 |
names = []
|
46 |
-
for i in ids:
|
47 |
-
|
|
|
|
|
|
|
48 |
recognition(imgs, ids, names, source_faces, d, source_imgs)
|
49 |
return ",".join(names), "Recognition.jpg"
|
50 |
|
51 |
detect = gr.Interface(
|
52 |
find_names,
|
53 |
-
gr.Image(type="filepath"),
|
54 |
-
["text",
|
55 |
examples = [
|
56 |
-
os.path.join(os.path.dirname(__file__), "examples/group1.jpg"),
|
57 |
-
os.path.join(os.path.dirname(__file__), "examples/group2.jpg")
|
58 |
]
|
59 |
)
|
60 |
|
@@ -106,8 +111,9 @@ i = 0
|
|
106 |
imgs = None
|
107 |
|
108 |
with gr.Blocks() as annotate:
|
109 |
-
|
110 |
-
|
|
|
111 |
with gr.Row():
|
112 |
next_btn = gr.Button(value="Next")
|
113 |
next_btn.click(load_image, inputs=[], outputs=[output, input])
|
|
|
24 |
try:
|
25 |
faces, id = extract_faces(detector, img)
|
26 |
source_faces.append(faces[id])
|
27 |
+
# source_faces.append(Image.open(img))
|
28 |
except Exception as e:
|
29 |
print(f"Skipping {img}, {e}")
|
30 |
|
31 |
source_embeddings = get_embeddings(model, source_faces)
|
32 |
|
33 |
+
def find_names(image, minSize, minConf):
|
34 |
imgs, _ = extract_faces(detector, image)
|
35 |
for i, face in enumerate(imgs):
|
36 |
+
print(face.size[0], face.size[1])
|
37 |
+
if(face.size[0] * face.size[1] < minSize):
|
38 |
del imgs[i]
|
39 |
|
40 |
embeds = get_embeddings(model, imgs)
|
41 |
+
print(len(embeds))
|
42 |
d = np.zeros((len(source_embeddings), len(embeds)))
|
43 |
for i, s in enumerate(source_embeddings):
|
44 |
for j, t in enumerate(embeds):
|
45 |
d[i][j] = findCosineDistance(s, t)
|
46 |
ids = np.argmin(d, axis = 0)
|
47 |
names = []
|
48 |
+
for j, i in enumerate(ids):
|
49 |
+
if 1 - d[i][j] > minConf:
|
50 |
+
names.append(source_imgs[i].split("/")[-1].split(".")[0])
|
51 |
+
else:
|
52 |
+
names.append("Unknown")
|
53 |
recognition(imgs, ids, names, source_faces, d, source_imgs)
|
54 |
return ",".join(names), "Recognition.jpg"
|
55 |
|
56 |
detect = gr.Interface(
|
57 |
find_names,
|
58 |
+
[gr.Image(type="filepath", label="Class Photo"), gr.Number(label = "Minimum Size"), gr.Number(label = "Minimum Confidence")],
|
59 |
+
["text" ,gr.Image(type = "filepath", label="Matching")],
|
60 |
examples = [
|
61 |
+
[os.path.join(os.path.dirname(__file__), "examples/group1.jpg"), 1000, 0.3],
|
62 |
+
[os.path.join(os.path.dirname(__file__), "examples/group2.jpg"), 1000, 0.3]
|
63 |
]
|
64 |
)
|
65 |
|
|
|
111 |
imgs = None
|
112 |
|
113 |
with gr.Blocks() as annotate:
|
114 |
+
with gr.Row():
|
115 |
+
input = gr.Textbox(label = "Enter Label")
|
116 |
+
output = gr.Image(type="pil", label="Image").style(height=400)
|
117 |
with gr.Row():
|
118 |
next_btn = gr.Button(value="Next")
|
119 |
next_btn.click(load_image, inputs=[], outputs=[output, input])
|