Spaces:
Running
Running
sebastiansarasti
commited on
Commit
•
d37300f
1
Parent(s):
1e850c7
removing the gradients in the model evaluation
Browse files
search.py
CHANGED
@@ -39,7 +39,9 @@ def process_text_for_encoder(text, model):
|
|
39 |
encoded_input = tokenizer(text, return_tensors='pt', padding='max_length', truncation=True, max_length=256)
|
40 |
input_ids = encoded_input['input_ids']
|
41 |
attention_mask = encoded_input['attention_mask']
|
42 |
-
|
|
|
|
|
43 |
return output.detach().numpy().tolist()[0]
|
44 |
|
45 |
def process_image_for_encoder(image, model):
|
@@ -50,7 +52,9 @@ def process_image_for_encoder(image, model):
|
|
50 |
return_tensors="pt",
|
51 |
do_resize=True
|
52 |
)['pixel_values']
|
53 |
-
|
|
|
|
|
54 |
return output.detach().numpy().tolist()[0]
|
55 |
|
56 |
def search_similarity(input, mode, top_k=5):
|
|
|
39 |
encoded_input = tokenizer(text, return_tensors='pt', padding='max_length', truncation=True, max_length=256)
|
40 |
input_ids = encoded_input['input_ids']
|
41 |
attention_mask = encoded_input['attention_mask']
|
42 |
+
model.eval()
|
43 |
+
with torch.no_grad():
|
44 |
+
output = model(input_ids=input_ids, attention_mask=attention_mask)
|
45 |
return output.detach().numpy().tolist()[0]
|
46 |
|
47 |
def process_image_for_encoder(image, model):
|
|
|
52 |
return_tensors="pt",
|
53 |
do_resize=True
|
54 |
)['pixel_values']
|
55 |
+
model.eval()
|
56 |
+
with torch.no_grad():
|
57 |
+
output = model(pixel_values=image_tensor)
|
58 |
return output.detach().numpy().tolist()[0]
|
59 |
|
60 |
def search_similarity(input, mode, top_k=5):
|