Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,28 +8,20 @@ from tensorflow.keras.applications import resnet
|
|
8 |
from tensorflow.keras import layers, Model
|
9 |
|
10 |
def create_embedding_model():
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
embedding_model = Model(base_cnn.input, output, name="Embedding")
|
21 |
-
|
22 |
-
trainable = False
|
23 |
-
for layer in base_cnn.layers:
|
24 |
-
if layer.name == "conv5_block1_out":
|
25 |
-
trainable = True
|
26 |
-
layer.trainable = trainable
|
27 |
-
|
28 |
return embedding_model
|
29 |
|
30 |
# Load the embedding model
|
31 |
embedding_model = create_embedding_model()
|
32 |
-
embedding_model.load_weights('
|
33 |
|
34 |
# Database to store embeddings and user IDs
|
35 |
user_embeddings = []
|
@@ -76,7 +68,7 @@ def recognize_user(image):
|
|
76 |
print(f"Min distance: {closest_distance}") # Debug: Print minimum distance
|
77 |
|
78 |
if closest_distance <= RECOGNITION_THRESHOLD:
|
79 |
-
return f"Recognized User: {closest_user_id}
|
80 |
else:
|
81 |
return f"User not recognized. Closest Distance: {closest_distance}"
|
82 |
except Exception as e:
|
@@ -104,4 +96,4 @@ def main():
|
|
104 |
demo.launch(share=True)
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
-
main()
|
|
|
8 |
from tensorflow.keras import layers, Model
|
9 |
|
10 |
def create_embedding_model():
|
11 |
+
# Load the model architecture
|
12 |
+
facenet_model = load_model('facenet_keras.h5', compile=False)
|
13 |
+
|
14 |
+
# Define the embedding model using FaceNet
|
15 |
+
embedding_model = Model(inputs=facenet_model.input,
|
16 |
+
outputs=facenet_model.layers[-2].output,
|
17 |
+
name="Embedding")
|
18 |
+
|
19 |
+
# Here, you don't need to set layers as trainable since it's already done in your training script
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
return embedding_model
|
21 |
|
22 |
# Load the embedding model
|
23 |
embedding_model = create_embedding_model()
|
24 |
+
embedding_model.load_weights('facenet_siamese_embedding.h5')
|
25 |
|
26 |
# Database to store embeddings and user IDs
|
27 |
user_embeddings = []
|
|
|
68 |
print(f"Min distance: {closest_distance}") # Debug: Print minimum distance
|
69 |
|
70 |
if closest_distance <= RECOGNITION_THRESHOLD:
|
71 |
+
return f"Recognized User: {closest_user_id}"
|
72 |
else:
|
73 |
return f"User not recognized. Closest Distance: {closest_distance}"
|
74 |
except Exception as e:
|
|
|
96 |
demo.launch(share=True)
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
+
main()
|