Shafeek Saleem commited on
Commit
45067dd
1 Parent(s): 7e37478

added face encodings page

Browse files
app.py CHANGED
@@ -13,19 +13,23 @@ def intro_page():
13
  st.subheader("Introduction")
14
 
15
  st.write(
16
- """Welcome to the interactive tutorial on creating your very own Face Recognition Application!
 
 
 
 
 
 
 
 
17
 
 
 
18
  In this tutorial, you will learn how to build a simple application that can detect and recognise faces from a given photo. Face recognition has revolutionized
19
- various industries, including security, entertainment, and personal identification.
20
-
21
- Are you ready to dive into the exciting world of face recognition?"""
22
  )
23
 
24
- # st.image(
25
- # "https://miro.medium.com/v2/resize:fit:720/0*Ko6oX3rRb0aTgdUI.gif",
26
- # use_column_width=True,
27
- # )
28
-
29
  st.info(f"Click on the button below to start the tutorial!")
30
 
31
  if st.button("I am Ready!"):
 
13
  st.subheader("Introduction")
14
 
15
  st.write(
16
+ """
17
+ Welcome to the interactive tutorial on creating your very own Face Recognition Application!
18
+ """
19
+ )
20
+
21
+ st.image(
22
+ "https://static.wixstatic.com/media/abb909_35aa4b27e4b840659a20fd69f0a18354~mv2.gif",
23
+ use_column_width=True,
24
+ )
25
 
26
+ st.write(
27
+ """
28
  In this tutorial, you will learn how to build a simple application that can detect and recognise faces from a given photo. Face recognition has revolutionized
29
+ various industries, including security, entertainment, and personal identification. Are you ready to dive into the exciting world of face recognition?
30
+ """
 
31
  )
32
 
 
 
 
 
 
33
  st.info(f"Click on the button below to start the tutorial!")
34
 
35
  if st.button("I am Ready!"):
pages/1_Technology Behind It.py CHANGED
@@ -27,22 +27,17 @@ def step1_page():
27
  2. **Face Encodings**: Next, the application pays attention to learn about face encodings, a technique that extracts unique
28
  facial characteristics and represents them as numerical vectors. These features capture unique characteristics that enable reliable comparisons between faces.
29
  Here we will generate face encodings for the known faces to create a data base.
30
- """
31
- )
32
- # st.image(
33
- # "https://media.istockphoto.com/id/1136827583/photo/futuristic-and-technological-scanning-of-face-for-facial-recognition.jpg?s=612x612&w=0&k=20&c=GsqBYxvE64TS8HY__OSn6qZU5HPBhIemnqjyf37TkQo=",
34
- # use_column_width=True,
35
- # )
36
- st.markdown(
37
- """
38
  3. **Face Recognition**: Dive into the world of face recognition algorithms, where you will understand the mechanisms
39
  behind comparing face encodings and making accurate matches. It uses the face encoding of unknown face against the face encodings of known faces to compare and find matching features.
40
  """
41
  )
42
- # st.image(
43
- # "https://miro.medium.com/v2/resize:fit:1200/1*4rjT-RSOTdlPqp1UwcF3tg.jpeg",
44
- # use_column_width=True,
45
- # )
 
 
46
  st.markdown(
47
  """
48
  So, our face recognition model is like a clever brain that looks at faces, notices important features, and identifies the person by name if it already knows their name.
 
27
  2. **Face Encodings**: Next, the application pays attention to learn about face encodings, a technique that extracts unique
28
  facial characteristics and represents them as numerical vectors. These features capture unique characteristics that enable reliable comparisons between faces.
29
  Here we will generate face encodings for the known faces to create a data base.
30
+
 
 
 
 
 
 
 
31
  3. **Face Recognition**: Dive into the world of face recognition algorithms, where you will understand the mechanisms
32
  behind comparing face encodings and making accurate matches. It uses the face encoding of unknown face against the face encodings of known faces to compare and find matching features.
33
  """
34
  )
35
+
36
+ st.image(
37
+ "https://user-images.githubusercontent.com/31125521/41526995-1a90e4e6-72e6-11e8-96d4-8b2ccdee5f79.gif",
38
+ use_column_width=True,
39
+ )
40
+
41
  st.markdown(
42
  """
43
  So, our face recognition model is like a clever brain that looks at faces, notices important features, and identifies the person by name if it already knows their name.
pages/2_Face Detection and Creating Database.py CHANGED
@@ -18,7 +18,7 @@ def step2_page():
18
 
19
  st.write(
20
  """
21
- ### Face Detection: How it works?
22
  Face detection is the process of identifying and locating human faces within an image or video frame.
23
  It is a fundamental step in many computer vision applications, including face recognition, facial expression analysis, and augmented reality.
24
  """
@@ -83,7 +83,7 @@ def step2_page():
83
  col.image(pil_image, use_column_width=True)
84
  face_name = st.text_input('Specify name', "This is a placeholder", key="text_"+str(i))
85
  if st.button("Save", key="button_"+str(i)):
86
- img_name = str(uuid.uuid4()) + f"{face_name}_{i}" + ".jpg"
87
  img_path = os.path.join(img_dir, img_name)
88
  pil_image.save(img_path)
89
  st.success("Face added successfully!")
 
18
 
19
  st.write(
20
  """
21
+ ### How it works?
22
  Face detection is the process of identifying and locating human faces within an image or video frame.
23
  It is a fundamental step in many computer vision applications, including face recognition, facial expression analysis, and augmented reality.
24
  """
 
83
  col.image(pil_image, use_column_width=True)
84
  face_name = st.text_input('Specify name', "This is a placeholder", key="text_"+str(i))
85
  if st.button("Save", key="button_"+str(i)):
86
+ img_name = str(uuid.uuid4()) + f"_{face_name}_{i}" + ".jpg"
87
  img_path = os.path.join(img_dir, img_name)
88
  pil_image.save(img_path)
89
  st.success("Face added successfully!")
pages/{3_Training the Model.py → 3_Face Encodings.py} RENAMED
@@ -1,9 +1,11 @@
1
  import streamlit as st
 
2
  from utils.levels import complete_level, render_page, initialize_level
3
  from utils.login import get_login, initialize_login
4
  from utils.inference import query
5
  import os
6
  import time
 
7
  import json
8
 
9
  initialize_login()
@@ -11,17 +13,6 @@ initialize_level()
11
 
12
  LEVEL = 3
13
 
14
-
15
- def infer(image):
16
- time.sleep(1)
17
- output = query(image)
18
- cols = st.columns(2)
19
- cols[0].image(image, use_column_width=True)
20
- with cols[1]:
21
- for item in output:
22
- st.progress(item["score"], text=item["label"])
23
-
24
-
25
  def step3_page():
26
  st.header("Feature encoding")
27
  st.markdown(
@@ -35,18 +26,10 @@ def step3_page():
35
  """
36
  )
37
  st.image(
38
- "https://1.bp.blogspot.com/-Cehw4NbX2L8/X1-DJeQgtmI/AAAAAAAAKeE/fA55q9EXsgQLU0trbgX_vJkiFMwR927yQCLcBGAsYHQ/s853/final.gif",
39
- use_column_width=True,
40
- )
41
- st.markdown(
42
- """
43
- 3. **Finding Patterns**: Our teacher starts to notice patterns in the pictures and the emotions we assigned to them. They might see that smiling faces usually mean happiness, or that certain features are common in sad expressions. These patterns help the teacher understand how emotions are expressed on people's faces.
44
- """
45
- )
46
- st.image(
47
- "https://miro.medium.com/v2/resize:fit:1358/1*KoHwRNZGrVrhdbye3BDEew.png",
48
  use_column_width=True,
49
  )
 
50
  st.markdown(
51
  """
52
  Once the face encodings are obtained, they can be stored in a database or used for face recognition tasks.
@@ -57,16 +40,16 @@ def step3_page():
57
  )
58
 
59
  st.info(
60
- "Now it's your turn to create face encodings to the face database you have created earlier!"
61
  )
62
 
63
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
64
  images = os.listdir(img_dir)
65
  if len(images) > 0:
66
- st.subheader("Lets see your available images in your known-face database.")
67
  cols = st.columns(len(images))
68
  for i, img in enumerate(images):
69
- face_name = img.split("_")[0]
70
  cols[i].image(os.path.join(img_dir, img), use_column_width=True)
71
  cols[i].write(face_name)
72
  st.subheader("Lets create face encodings for the known-faces.")
@@ -75,11 +58,10 @@ def step3_page():
75
  my_bar = st.progress(0, text="Generating encodings...")
76
  if len(images) > 0:
77
  for i, img in enumerate(images):
78
- with open(os.path.join(img_dir, img), "rb") as f:
79
- face_image = f.read()
80
  my_face_encoding = face_recognition.face_encodings(face_image)[0]
81
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating encodings...")
82
- face_encodings_dict[img] = my_face_encoding
83
  my_bar.progress(100, text="Successfully encoded all the known faces!")
84
  st.success("Face encoding completed successfully!")
85
  with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file:
 
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.inference import query
6
  import os
7
  import time
8
+ import face_recognition
9
  import json
10
 
11
  initialize_login()
 
13
 
14
  LEVEL = 3
15
 
 
 
 
 
 
 
 
 
 
 
 
16
  def step3_page():
17
  st.header("Feature encoding")
18
  st.markdown(
 
26
  """
27
  )
28
  st.image(
29
+ "https://miro.medium.com/v2/resize:fit:720/format:webp/1*V_wNVR0QvLQ7JZyUwMTv8w.jpeg",
 
 
 
 
 
 
 
 
 
30
  use_column_width=True,
31
  )
32
+
33
  st.markdown(
34
  """
35
  Once the face encodings are obtained, they can be stored in a database or used for face recognition tasks.
 
40
  )
41
 
42
  st.info(
43
+ "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!"
44
  )
45
 
46
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
47
  images = os.listdir(img_dir)
48
  if len(images) > 0:
49
+ st.subheader("Let's see your saved faces in your known-face database.")
50
  cols = st.columns(len(images))
51
  for i, img in enumerate(images):
52
+ face_name = img.split("_")[1]
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.")
 
58
  my_bar = st.progress(0, text="Generating encodings...")
59
  if len(images) > 0:
60
  for i, img in enumerate(images):
61
+ face_image = Image.open(os.path.join(img_dir, img))
 
62
  my_face_encoding = face_recognition.face_encodings(face_image)[0]
63
  my_bar.progress(int((i + 1) / len(images) * 100), text="Generating encodings...")
64
+ face_encodings_dict[img.split("_")[1]] = my_face_encoding
65
  my_bar.progress(100, text="Successfully encoded all the known faces!")
66
  st.success("Face encoding completed successfully!")
67
  with open(os.path.join(".sessions", get_login()["username"], "face_encodings.json"), "w") as write_file: