OpenCLIP
PyTorch
clip
dotREADYus commited on
Commit
d711a1d
·
verified ·
1 Parent(s): 13d68e4

Update README.md

Browse files

The 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.

Files changed (1) hide show
  1. README.md +2 -1
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
- text_probs = torch.sigmoid(image_features @ text_features.T * model.logit_scale.exp() + model.logit_bias)
 
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)