Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -94,7 +94,8 @@ def prod_function(transformer_model, prod_dl, prod_data):
|
|
94 |
accelerated_model.eval()
|
95 |
|
96 |
# Find Embedding of the image to be evaluated
|
97 |
-
|
|
|
98 |
|
99 |
prod_preds = []
|
100 |
|
@@ -186,8 +187,8 @@ prod_ds = dataset_prod_obj.create_dataset(image_paths, webcam=False)
|
|
186 |
prod_dl = DataLoader(prod_ds, batch_size=BATCH_SIZE)
|
187 |
|
188 |
# Testing the dataloader
|
189 |
-
|
190 |
-
|
191 |
|
192 |
# Read image from Camera
|
193 |
enable = st.checkbox("Enable camera")
|
@@ -205,13 +206,13 @@ if picture is not None:
|
|
205 |
prod_inputs = next(iter(webcam_dl))
|
206 |
st.write(prod_inputs['pixel_values'].shape)
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
94 |
accelerated_model.eval()
|
95 |
|
96 |
# Find Embedding of the image to be evaluated
|
97 |
+
with torch.no_grad():
|
98 |
+
emb_prod = accelerated_model(**acclerated_prod_data)
|
99 |
|
100 |
prod_preds = []
|
101 |
|
|
|
187 |
prod_dl = DataLoader(prod_ds, batch_size=BATCH_SIZE)
|
188 |
|
189 |
# Testing the dataloader
|
190 |
+
prod_inputs = next(iter(prod_dl))
|
191 |
+
st.write(prod_inputs['pixel_values'].shape)
|
192 |
|
193 |
# Read image from Camera
|
194 |
enable = st.checkbox("Enable camera")
|
|
|
206 |
prod_inputs = next(iter(webcam_dl))
|
207 |
st.write(prod_inputs['pixel_values'].shape)
|
208 |
|
209 |
+
# Run the predictions
|
210 |
+
prediction = prod_function(model_pretrained, prod_dl, webcam_dl)
|
211 |
+
predictions = torch.cat(prediction, 0).to(device)
|
212 |
+
match_idx = torch.argmin(predictions)
|
213 |
+
|
214 |
+
# Display the results
|
215 |
+
if predictions[match_idx] <= 0.3:
|
216 |
+
st.write('Welcome: ',image_paths[match_idx].split('/')[-1].split('.')[0])
|
217 |
+
else:
|
218 |
+
st.write("Match not found")
|