Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ class FaceEmbeddingModel(torch.nn.Module):
|
|
72 |
model_pretrained = torch.load(model_path, map_location=device, weights_only=False)
|
73 |
|
74 |
# Define the ML model - Evaluation function
|
75 |
-
def prod_function(transformer_model, prod_dl,
|
76 |
# Initialize accelerator
|
77 |
accelerator = Accelerator()
|
78 |
|
@@ -88,22 +88,23 @@ def prod_function(transformer_model, prod_dl, prod_data):
|
|
88 |
set_seed(42)
|
89 |
|
90 |
# There is no specific order to remember, we just need to unpack the objects in the same order we gave them to the prepare method.
|
91 |
-
accelerated_model, acclerated_prod_dl,
|
92 |
|
93 |
# Evaluate at the end of the epoch
|
94 |
accelerated_model.eval()
|
95 |
|
96 |
# Find Embedding of the image to be evaluated
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
100 |
|
101 |
prod_preds = []
|
102 |
|
103 |
for batch in acclerated_prod_dl:
|
104 |
-
img = batch['pixel_values']
|
105 |
with torch.no_grad():
|
106 |
-
emb = accelerated_model(
|
107 |
distance = F.pairwise_distance(emb, emb_prod)
|
108 |
|
109 |
prod_preds.append(distance)
|
|
|
72 |
model_pretrained = torch.load(model_path, map_location=device, weights_only=False)
|
73 |
|
74 |
# Define the ML model - Evaluation function
|
75 |
+
def prod_function(transformer_model, prod_dl, webcam_dl):
|
76 |
# Initialize accelerator
|
77 |
accelerator = Accelerator()
|
78 |
|
|
|
88 |
set_seed(42)
|
89 |
|
90 |
# There is no specific order to remember, we just need to unpack the objects in the same order we gave them to the prepare method.
|
91 |
+
accelerated_model, acclerated_prod_dl, acclerated_webcam_dl = accelerator.prepare(transformer_model, prod_dl, webcam_dl)
|
92 |
|
93 |
# Evaluate at the end of the epoch
|
94 |
accelerated_model.eval()
|
95 |
|
96 |
# Find Embedding of the image to be evaluated
|
97 |
+
for batch in acclerated_webcam_dl:
|
98 |
+
with torch.no_grad():
|
99 |
+
#img_prod = acclerated_prod_data['pixel_values']
|
100 |
+
emb_prod = accelerated_model(batch)
|
101 |
|
102 |
prod_preds = []
|
103 |
|
104 |
for batch in acclerated_prod_dl:
|
105 |
+
#img = batch['pixel_values']
|
106 |
with torch.no_grad():
|
107 |
+
emb = accelerated_model(batch)
|
108 |
distance = F.pairwise_distance(emb, emb_prod)
|
109 |
|
110 |
prod_preds.append(distance)
|