RobotJelly commited on
Commit
1e68ee0
·
1 Parent(s): 27b8fd9
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -52,7 +52,9 @@ def encode_search_query(search_query, model, device):
52
  #text_encoded = model.encode_text(clip.tokenize(search_query).to(device))
53
  #text_encoded /= text_encoded.norm(dim=-1, keepdim=True)
54
  # Retrieve the feature vector from the GPU and convert it to a numpy array
55
- return model.get_text_features(**inputs).cpu().numpy()
 
 
56
  #return text_encoded.cpu().numpy()
57
 
58
  # Find all matched photos
@@ -91,7 +93,8 @@ def image_search(search_text, search_image, option):
91
  processed_image = processor(text=None, images=search_image, return_tensors="pt", padding=True)["pixel_values"]
92
  image_feature = model.get_image_features(processed_image.to(device))
93
  image_feature /= image_feature.norm(dim=-1, keepdim=True)
94
- image_feature = image_feature.cpu().numpy()
 
95
  # Find the matched Images
96
  matched_images = find_matches(image_feature, photo_features, photo_ids, 4)
97
  #is_input_image = True
 
52
  #text_encoded = model.encode_text(clip.tokenize(search_query).to(device))
53
  #text_encoded /= text_encoded.norm(dim=-1, keepdim=True)
54
  # Retrieve the feature vector from the GPU and convert it to a numpy array
55
+ text_features = model.get_text_features(**inputs).detach().numpy()
56
+ #text_features = model.get_text_features(**inputs).cpu().numpy()
57
+ return text_features
58
  #return text_encoded.cpu().numpy()
59
 
60
  # Find all matched photos
 
93
  processed_image = processor(text=None, images=search_image, return_tensors="pt", padding=True)["pixel_values"]
94
  image_feature = model.get_image_features(processed_image.to(device))
95
  image_feature /= image_feature.norm(dim=-1, keepdim=True)
96
+ #image_feature = image_feature.cpu().numpy()
97
+ image_feature = image_feature.detach().numpy()
98
  # Find the matched Images
99
  matched_images = find_matches(image_feature, photo_features, photo_ids, 4)
100
  #is_input_image = True