Shafeek Saleem commited on
Commit
e87299f
1 Parent(s): f36346b

added face encodings pagejj

Browse files
Files changed (1) hide show
  1. pages/3_Face Encodings.py +7 -4
pages/3_Face Encodings.py CHANGED
@@ -53,18 +53,21 @@ def step3_page():
53
  cols[i].image(os.path.join(img_dir, img), use_column_width=True)
54
  cols[i].write(face_name)
55
  st.subheader("Lets create face encodings for the known-faces.")
56
- face_encodings_dict = {}
57
  if st.button("Create Face Encodings"):
58
  my_bar = st.progress(0, text="Generating face encodings...")
59
  if len(images) > 0:
60
  for i, img in enumerate(images):
61
  face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
 
62
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
63
- face_encodings_dict[img.split("_")[1]] = face_recognition.face_encodings(face_image).tolist()
 
 
64
  my_bar.progress(100, text="Successfully encoded all the known faces!")
65
  st.success("Face encoding completed successfully!")
66
- with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
67
- json.dump(face_encodings_dict, write_file, indent=4)
68
  complete_level(LEVEL)
69
  else:
70
  my_bar.empty()
 
53
  cols[i].image(os.path.join(img_dir, img), use_column_width=True)
54
  cols[i].write(face_name)
55
  st.subheader("Lets create face encodings for the known-faces.")
56
+ # face_encodings_dict = {}
57
  if st.button("Create Face Encodings"):
58
  my_bar = st.progress(0, text="Generating face encodings...")
59
  if len(images) > 0:
60
  for i, img in enumerate(images):
61
  face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
62
+ my_face_encoding = face_recognition.face_encodings(face_image)
63
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
64
+ with open(os.path.join(".sessions", get_login()["username"], img.split("_")[1]+".npy"), 'wb') as f:
65
+ np.save(f, my_face_encoding)
66
+ # face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
67
  my_bar.progress(100, text="Successfully encoded all the known faces!")
68
  st.success("Face encoding completed successfully!")
69
+ # with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
70
+ # json.dump(face_encodings_dict, write_file, indent=4)
71
  complete_level(LEVEL)
72
  else:
73
  my_bar.empty()