Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -68,9 +68,6 @@ def extract_hog_features(img):
|
|
68 |
return hog_features
|
69 |
|
70 |
def get_face(img):
|
71 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
72 |
-
img = img.astype(np.float32) / 255.0
|
73 |
-
|
74 |
detector = MTCNN()
|
75 |
faces = detector.detect_faces(img)
|
76 |
if faces:
|
@@ -86,16 +83,21 @@ def verify(image, model, person):
|
|
86 |
temp_image.write(image.read())
|
87 |
temp_image_path = temp_image.name
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
siamese.eval()
|
93 |
-
|
94 |
-
image = Image.open(temp_image_path)
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
|
|
99 |
face = preprocess_image_siamese(face)
|
100 |
|
101 |
with torch.no_grad():
|
@@ -107,20 +109,15 @@ def verify(image, model, person):
|
|
107 |
st.write("Match")
|
108 |
else:
|
109 |
st.write("Not Match")
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
image = cv2.imread(temp_image_path)
|
120 |
-
|
121 |
-
face = get_face(image)
|
122 |
-
|
123 |
-
if face is not None:
|
124 |
face = preprocess_image_svm(face)
|
125 |
|
126 |
hog = extract_hog_features(face)
|
@@ -133,8 +130,6 @@ def verify(image, model, person):
|
|
133 |
st.write("Match")
|
134 |
else:
|
135 |
st.write("Not Match")
|
136 |
-
else:
|
137 |
-
st.write("Face not detected")
|
138 |
|
139 |
def main():
|
140 |
st.title("Face Verification")
|
|
|
68 |
return hog_features
|
69 |
|
70 |
def get_face(img):
|
|
|
|
|
|
|
71 |
detector = MTCNN()
|
72 |
faces = detector.detect_faces(img)
|
73 |
if faces:
|
|
|
83 |
temp_image.write(image.read())
|
84 |
temp_image_path = temp_image.name
|
85 |
|
86 |
+
image = cv2.imread(temp_image_path)
|
87 |
+
|
88 |
+
face = get_face(image)
|
|
|
|
|
|
|
89 |
|
90 |
+
temp_face_path = tempfile.mktemp(suffix=".jpg")
|
91 |
+
cv2.imwrite(temp_face_path, face)
|
92 |
+
|
93 |
+
if face is not None:
|
94 |
+
if model == "Siamese":
|
95 |
+
siamese = SiameseNetwork()
|
96 |
+
siamese.load_state_dict(torch.load(f'siamese_{person.lower()}.pth'))
|
97 |
+
siamese.eval()
|
98 |
|
99 |
+
face = Image.load(temp_face_path)
|
100 |
+
|
101 |
face = preprocess_image_siamese(face)
|
102 |
|
103 |
with torch.no_grad():
|
|
|
109 |
st.write("Match")
|
110 |
else:
|
111 |
st.write("Not Match")
|
112 |
+
|
113 |
+
elif model == "HOG-SVM":
|
114 |
+
with open(f'./svm_{person.lower()}.pkl', 'rb') as f:
|
115 |
+
svm = joblib.load(f)
|
116 |
+
with open(f'./pca_{person.lower()}.pkl', 'rb') as f:
|
117 |
+
pca = joblib.load(f)
|
118 |
+
|
119 |
+
face = cv2.imread(temp_face_path)
|
120 |
+
|
|
|
|
|
|
|
|
|
|
|
121 |
face = preprocess_image_svm(face)
|
122 |
|
123 |
hog = extract_hog_features(face)
|
|
|
130 |
st.write("Match")
|
131 |
else:
|
132 |
st.write("Not Match")
|
|
|
|
|
133 |
|
134 |
def main():
|
135 |
st.title("Face Verification")
|