Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ from skimage.feature import hog
|
|
8 |
import joblib
|
9 |
import numpy as np
|
10 |
|
11 |
-
# Preprocessing for Siamese Model
|
12 |
def preprocess_image_siamese(img):
|
13 |
transform = transforms.Compose([
|
14 |
transforms.Resize((224, 224)),
|
@@ -17,18 +16,15 @@ def preprocess_image_siamese(img):
|
|
17 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
18 |
return transform(img)
|
19 |
|
20 |
-
# Preprocessing for SVM model (converting to grayscale)
|
21 |
def preprocess_image_svm(img):
|
22 |
img = cv2.resize(img, (224, 224))
|
23 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
24 |
return img
|
25 |
|
26 |
-
# Extract HOG Features
|
27 |
def extract_hog_features(img):
|
28 |
hog_features = hog(img, orientations=9, pixels_per_cell=(16, 16), cells_per_block=(4, 4))
|
29 |
return hog_features
|
30 |
|
31 |
-
# Detect faces using MTCNN
|
32 |
def get_face(img):
|
33 |
detector = MTCNN()
|
34 |
faces = detector.detect_faces(img)
|
@@ -39,7 +35,6 @@ def get_face(img):
|
|
39 |
return img[y1:y2, x1:x2]
|
40 |
return None
|
41 |
|
42 |
-
# Function to verify face (either HOG-SVM or Siamese model)
|
43 |
def verify(image, model, person):
|
44 |
|
45 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_image:
|
@@ -51,7 +46,7 @@ def verify(image, model, person):
|
|
51 |
face = get_face(image)
|
52 |
|
53 |
if face is not None:
|
54 |
-
if
|
55 |
with open(f'./svm_{lower(person)}.pkl', 'rb') as f:
|
56 |
svm = joblib.load(f)
|
57 |
with open(f'./pca_{lower(person)}.pkl', 'rb') as f:
|
@@ -70,9 +65,8 @@ def verify(image, model, person):
|
|
70 |
else:
|
71 |
st.write("Not Match")
|
72 |
else:
|
73 |
-
st.write("Face not detected
|
74 |
|
75 |
-
# Main function to handle Streamlit interaction
|
76 |
def main():
|
77 |
st.title("Real-time Face Verification App")
|
78 |
|
|
|
8 |
import joblib
|
9 |
import numpy as np
|
10 |
|
|
|
11 |
def preprocess_image_siamese(img):
|
12 |
transform = transforms.Compose([
|
13 |
transforms.Resize((224, 224)),
|
|
|
16 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
17 |
return transform(img)
|
18 |
|
|
|
19 |
def preprocess_image_svm(img):
|
20 |
img = cv2.resize(img, (224, 224))
|
21 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
22 |
return img
|
23 |
|
|
|
24 |
def extract_hog_features(img):
|
25 |
hog_features = hog(img, orientations=9, pixels_per_cell=(16, 16), cells_per_block=(4, 4))
|
26 |
return hog_features
|
27 |
|
|
|
28 |
def get_face(img):
|
29 |
detector = MTCNN()
|
30 |
faces = detector.detect_faces(img)
|
|
|
35 |
return img[y1:y2, x1:x2]
|
36 |
return None
|
37 |
|
|
|
38 |
def verify(image, model, person):
|
39 |
|
40 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_image:
|
|
|
46 |
face = get_face(image)
|
47 |
|
48 |
if face is not None:
|
49 |
+
if model == "HOG-SVM":
|
50 |
with open(f'./svm_{lower(person)}.pkl', 'rb') as f:
|
51 |
svm = joblib.load(f)
|
52 |
with open(f'./pca_{lower(person)}.pkl', 'rb') as f:
|
|
|
65 |
else:
|
66 |
st.write("Not Match")
|
67 |
else:
|
68 |
+
st.write("Face not detected")
|
69 |
|
|
|
70 |
def main():
|
71 |
st.title("Real-time Face Verification App")
|
72 |
|