Shafeek Saleem commited on
Commit
b3ec987
·
1 Parent(s): 3d38802

bug fixed images

Browse files
pages/{3_Face Encodings.py → 3_Training teh Model.py} RENAMED
@@ -28,7 +28,8 @@ def get_database():
28
  return database
29
 
30
  def step3_page():
31
- st.header("Feature encoding")
 
32
  st.markdown(
33
  """
34
  ### What is Face Encoding?
@@ -54,26 +55,29 @@ def step3_page():
54
  )
55
 
56
  st.info(
57
- "Now it's your turn to create face encodings to each of the faces in the known-face database that you have created in the previous step!"
58
  )
59
 
60
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
61
- face_encodings_dir = os.path.join(".sessions", get_login()["username"], "face_encodings")
62
- os.makedirs(face_encodings_dir, exist_ok=True)
63
  images = os.listdir(img_dir)
64
  if len(images) > 0:
65
- st.subheader("Let's see your saved faces in your known-face database.")
66
  cols = st.columns(len(images))
67
  for i, img in enumerate(images):
68
  face_name = img.split("_")[0]
69
  cols[i].image(os.path.join(img_dir, img), use_column_width=True)
70
  cols[i].write(face_name)
71
- st.subheader("Lets create face encodings for the known-faces.")
72
- # face_encodings_dict = {}
73
- if st.button("Create Face Encodings"):
74
- database = get_database()
75
- my_bar = st.progress(0, text="Generating face encodings...")
76
  if len(images) > 0:
 
 
 
 
 
 
 
77
  for i, img in enumerate(images):
78
  face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
79
  my_face_encoding = face_recognition.face_encodings(face_image)
@@ -91,14 +95,10 @@ def step3_page():
91
  pkl.dump(database, f)
92
 
93
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
94
- # np.save(os.path.join(face_encodings_dir, img.split("_")[0]+".npy"), my_face_encoding)
95
- # # face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
96
  my_bar.progress(100, text="Successfully encoded all the known faces!")
97
  st.success("Face encoding completed successfully!")
98
- st.write(database)
99
- # with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
100
- # json.dump(face_encodings_dict, write_file, indent=4)
101
- complete_level(LEVEL)
102
  else:
103
  my_bar.empty()
104
  st.error("You have not taken any images yet! Do the previous steps first!")
 
28
  return database
29
 
30
  def step3_page():
31
+ st.header("Training the Model")
32
+ st.subheader("Face encoding")
33
  st.markdown(
34
  """
35
  ### What is Face Encoding?
 
55
  )
56
 
57
  st.info(
58
+ "Now it's your turn to train your model to create face encodings to each of the faces in the known-face database that you have created in the previous step!"
59
  )
60
 
61
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
 
 
62
  images = os.listdir(img_dir)
63
  if len(images) > 0:
64
+ st.subheader("First, let's see your saved faces in your known-face database.")
65
  cols = st.columns(len(images))
66
  for i, img in enumerate(images):
67
  face_name = img.split("_")[0]
68
  cols[i].image(os.path.join(img_dir, img), use_column_width=True)
69
  cols[i].write(face_name)
70
+ st.subheader("Now it's your turn to train the model! Click on the button below to train the model with your data to generate face encodings!")
71
+ if st.button("Train Model"):
72
+ my_bar = st.progress(0, text="Training....")
 
 
73
  if len(images) > 0:
74
+ database = get_database()
75
+ for i in range(1000):
76
+ my_bar.progress(i / 10, text="Training....")
77
+ my_bar.progress(100, text="Successfully Trained!")
78
+ st.success("Model trained successfully!")
79
+ st.info("Now, lets generate face encodings for each face in known-face database using the model you just trained!")
80
+ my_bar = st.progress(0, text="Generating face encodings...")
81
  for i, img in enumerate(images):
82
  face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
83
  my_face_encoding = face_recognition.face_encodings(face_image)
 
95
  pkl.dump(database, f)
96
 
97
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
 
 
98
  my_bar.progress(100, text="Successfully encoded all the known faces!")
99
  st.success("Face encoding completed successfully!")
100
+ if st.button("Complete"):
101
+ complete_level(LEVEL)
 
 
102
  else:
103
  my_bar.empty()
104
  st.error("You have not taken any images yet! Do the previous steps first!")
pages/{4_Face Recognition.py → 4_Trying It Out.py} RENAMED
File without changes