Update README.md
Browse filesThe original code sample would throw this error ```TypeError: unsupported operand type(s) for +: 'Tensor' and 'NoneType'```.
Per https://github.com/mlfoundations/open_clip/issues/736#issuecomment-1801879013, the updated sample will run without issue.
README.md
CHANGED
@@ -91,7 +91,8 @@ with torch.no_grad(), torch.cuda.amp.autocast():
|
|
91 |
image_features = F.normalize(image_features, dim=-1)
|
92 |
text_features = F.normalize(text_features, dim=-1)
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
zipped_list = list(zip(labels_list, [round(p.item(), 3) for p in text_probs[0]]))
|
97 |
print("Label probabilities: ", zipped_list)
|
|
|
91 |
image_features = F.normalize(image_features, dim=-1)
|
92 |
text_features = F.normalize(text_features, dim=-1)
|
93 |
|
94 |
+
logits = model.logit_scale.exp() * image_features @ text_features.T
|
95 |
+
probs = logits.softmax(dim=-1)
|
96 |
|
97 |
zipped_list = list(zip(labels_list, [round(p.item(), 3) for p in text_probs[0]]))
|
98 |
print("Label probabilities: ", zipped_list)
|