Spaces:
Sleeping
Sleeping
Bill Psomas
commited on
Commit
·
bdefe5d
1
Parent(s):
00058d0
fix for running on cpu
Browse files
app.py
CHANGED
|
@@ -24,17 +24,18 @@ def calculate_similarity(image_features, text_feature, lambda_val=0.5):
|
|
| 24 |
|
| 25 |
# Load precomputed features
|
| 26 |
features = load_features('features/patternnet_clip.pkl')
|
| 27 |
-
image_features = torch.tensor(features['feats'])
|
| 28 |
image_paths = features['paths']
|
| 29 |
|
| 30 |
def image_text_retrieval(image, text, lambda_val):
|
| 31 |
# Preprocess image
|
| 32 |
preprocess = open_clip.get_preprocess('ViT-L-14')
|
| 33 |
-
image = preprocess(image).unsqueeze(0)
|
| 34 |
|
| 35 |
# Encode image and text
|
| 36 |
image_feature = model.encode_image(image).cpu()
|
| 37 |
-
text_feature = model.encode_text(tokenizer(text).unsqueeze(0).cuda()).cpu()
|
|
|
|
| 38 |
|
| 39 |
# Calculate combined similarities
|
| 40 |
similarities = calculate_similarity(image_features, text_feature, lambda_val)
|
|
|
|
| 24 |
|
| 25 |
# Load precomputed features
|
| 26 |
features = load_features('features/patternnet_clip.pkl')
|
| 27 |
+
image_features = torch.tensor(features['feats'])#.cuda()
|
| 28 |
image_paths = features['paths']
|
| 29 |
|
| 30 |
def image_text_retrieval(image, text, lambda_val):
|
| 31 |
# Preprocess image
|
| 32 |
preprocess = open_clip.get_preprocess('ViT-L-14')
|
| 33 |
+
image = preprocess(image).unsqueeze(0)#.cuda()
|
| 34 |
|
| 35 |
# Encode image and text
|
| 36 |
image_feature = model.encode_image(image).cpu()
|
| 37 |
+
#text_feature = model.encode_text(tokenizer(text).unsqueeze(0).cuda()).cpu()
|
| 38 |
+
text_feature = model.encode_text(tokenizer(text).unsqueeze(0)).cpu()
|
| 39 |
|
| 40 |
# Calculate combined similarities
|
| 41 |
similarities = calculate_similarity(image_features, text_feature, lambda_val)
|