Spaces:
Runtime error
Runtime error
Shafeek Saleem
commited on
Commit
·
a0b7ae5
1
Parent(s):
eb30d87
bug fixed images
Browse files- dataset/database.pkl +0 -0
- pages/3_Face Encodings.py +26 -2
dataset/database.pkl
ADDED
|
File without changes
|
pages/3_Face Encodings.py
CHANGED
|
@@ -8,12 +8,21 @@ import time
|
|
| 8 |
import face_recognition
|
| 9 |
import json
|
| 10 |
import numpy as np
|
|
|
|
| 11 |
|
| 12 |
initialize_login()
|
| 13 |
initialize_level()
|
| 14 |
|
| 15 |
LEVEL = 3
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def step3_page():
|
| 18 |
st.header("Feature encoding")
|
| 19 |
st.markdown(
|
|
@@ -58,16 +67,31 @@ def step3_page():
|
|
| 58 |
st.subheader("Lets create face encodings for the known-faces.")
|
| 59 |
# face_encodings_dict = {}
|
| 60 |
if st.button("Create Face Encodings"):
|
|
|
|
| 61 |
my_bar = st.progress(0, text="Generating face encodings...")
|
| 62 |
if len(images) > 0:
|
| 63 |
for i, img in enumerate(images):
|
| 64 |
face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
|
| 65 |
my_face_encoding = face_recognition.face_encodings(face_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
|
| 67 |
-
np.save(os.path.join(face_encodings_dir, img.split("_")[0]+".npy"), my_face_encoding)
|
| 68 |
-
# face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
|
| 69 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
| 70 |
st.success("Face encoding completed successfully!")
|
|
|
|
| 71 |
# with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
|
| 72 |
# json.dump(face_encodings_dict, write_file, indent=4)
|
| 73 |
complete_level(LEVEL)
|
|
|
|
| 8 |
import face_recognition
|
| 9 |
import json
|
| 10 |
import numpy as np
|
| 11 |
+
from collections import defaultdict
|
| 12 |
|
| 13 |
initialize_login()
|
| 14 |
initialize_level()
|
| 15 |
|
| 16 |
LEVEL = 3
|
| 17 |
|
| 18 |
+
PKL_PATH = 'dataset/database.pkl'
|
| 19 |
+
information = defaultdict(dict)
|
| 20 |
+
|
| 21 |
+
def get_database():
|
| 22 |
+
with open(PKL_PATH,'rb') as f:
|
| 23 |
+
database = pkl.load(f)
|
| 24 |
+
return database
|
| 25 |
+
|
| 26 |
def step3_page():
|
| 27 |
st.header("Feature encoding")
|
| 28 |
st.markdown(
|
|
|
|
| 67 |
st.subheader("Lets create face encodings for the known-faces.")
|
| 68 |
# face_encodings_dict = {}
|
| 69 |
if st.button("Create Face Encodings"):
|
| 70 |
+
database = get_database()
|
| 71 |
my_bar = st.progress(0, text="Generating face encodings...")
|
| 72 |
if len(images) > 0:
|
| 73 |
for i, img in enumerate(images):
|
| 74 |
face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
|
| 75 |
my_face_encoding = face_recognition.face_encodings(face_image)
|
| 76 |
+
face_name = img.split("_")[0]
|
| 77 |
+
face_id = img.split(".")[0]
|
| 78 |
+
|
| 79 |
+
# check if id already exists
|
| 80 |
+
existing_id = [i for i in database.keys()]
|
| 81 |
+
if face_id in existing_id:
|
| 82 |
+
st.error(f"Encoding already created for : {face_id}")
|
| 83 |
+
else:
|
| 84 |
+
database[face_id] = {'name': face_name,
|
| 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 |
+
# np.save(os.path.join(face_encodings_dir, img.split("_")[0]+".npy"), my_face_encoding)
|
| 91 |
+
# # face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
|
| 92 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
| 93 |
st.success("Face encoding completed successfully!")
|
| 94 |
+
st.write(database)
|
| 95 |
# with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
|
| 96 |
# json.dump(face_encodings_dict, write_file, indent=4)
|
| 97 |
complete_level(LEVEL)
|