Rajagopal commited on
Commit
41332b4
·
1 Parent(s): ecf0e06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -93,6 +93,31 @@ def doubleimage_text_zeroshot(image, image2, text_list):
93
  with torch.no_grad():
94
  embeddings = model(inputs)
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
 
98
 
 
93
  with torch.no_grad():
94
  embeddings = model(inputs)
95
 
96
+ scores = (
97
+ torch.softmax(
98
+ embeddings[ModalityType.VISION] @ embeddings[ModalityType.TEXT].T, dim=-1
99
+ )
100
+ .squeeze(0)
101
+ .tolist()
102
+ )
103
+
104
+ score_dict = {label: score for label, score in zip(labels, scores)}
105
+
106
+ return score_dict
107
+
108
+
109
+
110
+ def doubleimage_text_zeroshotOLD(image, image2, text_list):
111
+ image_paths = [image, image2]
112
+ labels = [label.strip(" ") for label in text_list.strip(" ").split("|")]
113
+ inputs = {
114
+ ModalityType.TEXT: data.load_and_transform_text(labels, device),
115
+ ModalityType.VISION: data.load_and_transform_vision_data(image_paths, device),
116
+ }
117
+
118
+ with torch.no_grad():
119
+ embeddings = model(inputs)
120
+
121
 
122
 
123