Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
import cv2
|
| 5 |
import os
|
| 6 |
from scipy.spatial.distance import cosine
|
| 7 |
-
from tensorflow.keras.
|
| 8 |
from tensorflow.keras import layers, Model
|
| 9 |
|
| 10 |
def create_embedding_model():
|
|
@@ -32,8 +32,15 @@ RECOGNITION_THRESHOLD = 0.1 # Adjust as needed
|
|
| 32 |
|
| 33 |
# Preprocess the image
|
| 34 |
def preprocess_image(image):
|
| 35 |
-
|
| 36 |
-
image =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return np.expand_dims(image, axis=0)
|
| 38 |
|
| 39 |
# Generate embedding
|
|
|
|
| 4 |
import cv2
|
| 5 |
import os
|
| 6 |
from scipy.spatial.distance import cosine
|
| 7 |
+
from tensorflow.keras.models import load_model
|
| 8 |
from tensorflow.keras import layers, Model
|
| 9 |
|
| 10 |
def create_embedding_model():
|
|
|
|
| 32 |
|
| 33 |
# Preprocess the image
|
| 34 |
def preprocess_image(image):
|
| 35 |
+
# Resize image to match FaceNet input size (160x160)
|
| 36 |
+
image = cv2.resize(image, (160, 160))
|
| 37 |
+
|
| 38 |
+
# Normalize the image to a range of [-1, 1] as FaceNet might expect
|
| 39 |
+
image = image.astype('float32')
|
| 40 |
+
mean, std = image.mean(), image.std()
|
| 41 |
+
image = (image - mean) / std
|
| 42 |
+
|
| 43 |
+
# Expand dimensions to add batch size of 1
|
| 44 |
return np.expand_dims(image, axis=0)
|
| 45 |
|
| 46 |
# Generate embedding
|