Spaces:
Runtime error
Runtime error
Shafeek Saleem
commited on
Commit
·
68c2ecc
1
Parent(s):
c8dbc56
bug fixed
Browse files- pages/3_Training the Model.py +3 -1
- pages/4_Trying It Out.py +4 -3
- utils/inference.py +3 -3
pages/3_Training the Model.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
|
|
|
| 3 |
from utils.levels import complete_level, render_page, initialize_level
|
| 4 |
from utils.login import get_login, initialize_login
|
| 5 |
from utils.database import get_database
|
|
@@ -64,6 +65,7 @@ def step3_page():
|
|
| 64 |
if len(images) > 0:
|
| 65 |
database = get_database(PKL_PATH)
|
| 66 |
for i in range(100):
|
|
|
|
| 67 |
my_bar.progress(i, text="Training....")
|
| 68 |
my_bar.progress(100, text="Successfully Trained!")
|
| 69 |
st.success("Model trained successfully!")
|
|
@@ -85,7 +87,7 @@ def step3_page():
|
|
| 85 |
'encoding': my_face_encoding}
|
| 86 |
with open(PKL_PATH, 'wb') as f:
|
| 87 |
pkl.dump(database, f)
|
| 88 |
-
|
| 89 |
my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
|
| 90 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
| 91 |
st.success("Face encoding completed successfully!")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
+
import time
|
| 4 |
from utils.levels import complete_level, render_page, initialize_level
|
| 5 |
from utils.login import get_login, initialize_login
|
| 6 |
from utils.database import get_database
|
|
|
|
| 65 |
if len(images) > 0:
|
| 66 |
database = get_database(PKL_PATH)
|
| 67 |
for i in range(100):
|
| 68 |
+
time.sleep(0.1)
|
| 69 |
my_bar.progress(i, text="Training....")
|
| 70 |
my_bar.progress(100, text="Successfully Trained!")
|
| 71 |
st.success("Model trained successfully!")
|
|
|
|
| 87 |
'encoding': my_face_encoding}
|
| 88 |
with open(PKL_PATH, 'wb') as f:
|
| 89 |
pkl.dump(database, f)
|
| 90 |
+
time.sleep(0.5)
|
| 91 |
my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
|
| 92 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
| 93 |
st.success("Face encoding completed successfully!")
|
pages/4_Trying It Out.py
CHANGED
|
@@ -32,9 +32,10 @@ def step4_page():
|
|
| 32 |
st.info("Select your input type to analyze!")
|
| 33 |
input_type = st.radio("Select the Input Type", ["Image upload", "Camera"])
|
| 34 |
# Put slide to adjust tolerance
|
| 35 |
-
tolerance =
|
| 36 |
-
st.
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
if input_type == "Image upload":
|
| 40 |
st.title("Face Recognition App")
|
|
|
|
| 32 |
st.info("Select your input type to analyze!")
|
| 33 |
input_type = st.radio("Select the Input Type", ["Image upload", "Camera"])
|
| 34 |
# Put slide to adjust tolerance
|
| 35 |
+
tolerance = 0.14
|
| 36 |
+
# tolerance = st.slider("Tolerance", 0.0, 1.0, 0.15, 0.01)
|
| 37 |
+
# st.info(
|
| 38 |
+
# "Tolerance is the threshold for face recognition. The lower the tolerance, the more strict the face recognition. The higher the tolerance, the more loose the face recognition.")
|
| 39 |
|
| 40 |
if input_type == "Image upload":
|
| 41 |
st.title("Face Recognition App")
|
utils/inference.py
CHANGED
|
@@ -17,7 +17,7 @@ def recognize(image,tolerance):
|
|
| 17 |
face_encodings = face_recognition.face_encodings(image,face_locations)
|
| 18 |
for (top,right,bottom,left), face_encoding in zip(face_locations,face_encodings):
|
| 19 |
matches = face_recognition.compare_faces(known_encoding,face_encoding,tolerance=tolerance)
|
| 20 |
-
distance = face_recognition.face_distance(known_encoding,face_encoding)
|
| 21 |
name = 'Unknown'
|
| 22 |
face_id = 'Unknown'
|
| 23 |
for i in range(len(matches)):
|
|
@@ -25,8 +25,8 @@ def recognize(image,tolerance):
|
|
| 25 |
match_index = i
|
| 26 |
name = database[match_index]['name']
|
| 27 |
face_id = database[match_index]['face_id'].split("_")[1]
|
| 28 |
-
distance = round(np.sum(distance[match_index]),2)
|
| 29 |
-
cv2.putText(image,str(distance),(left,top-30),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
|
| 30 |
break
|
| 31 |
cv2.rectangle(image,(left,top),(right,bottom),(0,255,0),2)
|
| 32 |
cv2.putText(image,name,(left,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
|
|
|
|
| 17 |
face_encodings = face_recognition.face_encodings(image,face_locations)
|
| 18 |
for (top,right,bottom,left), face_encoding in zip(face_locations,face_encodings):
|
| 19 |
matches = face_recognition.compare_faces(known_encoding,face_encoding,tolerance=tolerance)
|
| 20 |
+
# distance = face_recognition.face_distance(known_encoding,face_encoding)
|
| 21 |
name = 'Unknown'
|
| 22 |
face_id = 'Unknown'
|
| 23 |
for i in range(len(matches)):
|
|
|
|
| 25 |
match_index = i
|
| 26 |
name = database[match_index]['name']
|
| 27 |
face_id = database[match_index]['face_id'].split("_")[1]
|
| 28 |
+
# distance = round(np.sum(distance[match_index]),2)
|
| 29 |
+
# cv2.putText(image,str(distance),(left,top-30),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
|
| 30 |
break
|
| 31 |
cv2.rectangle(image,(left,top),(right,bottom),(0,255,0),2)
|
| 32 |
cv2.putText(image,name,(left,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
|