xuemduan commited on
Commit
661cbef
·
verified ·
1 Parent(s): d134079

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -5
README.md CHANGED
@@ -69,11 +69,14 @@ model = CLIPModel.from_pretrained("xuemduan/reevaluate-clip")
69
  processor = CLIPProcessor.from_pretrained("xuemduan/reevaluate-clip")
70
 
71
  image = Image.open("artefact.jpg")
72
- text = "yellow flower paintings by Van Gogh between 1887 and 1889"
73
 
74
- inputs = processor(text=[text], images=image, return_tensors="pt", padding=True)
75
- outputs = model(**inputs)
76
 
77
- # Compute similarity
78
- similarity = outputs.logits_per_image.softmax(dim=-1)
 
 
 
79
  print(similarity)
 
69
  processor = CLIPProcessor.from_pretrained("xuemduan/reevaluate-clip")
70
 
71
  image = Image.open("artefact.jpg")
72
+ text = "yellow flower paintings"
73
 
74
+ image_embeds = model.get_image_features(**processor(images=image, return_tensors="pt"))
75
+ text_embeds = model.get_text_features(**processor(text=[text], return_tensors="pt"))
76
 
77
+ # normalize
78
+ image_embeds = image_embeds / image_embeds.norm(dim=-1, keepdim=True)
79
+ text_embeds = text_embeds / text_embeds.norm(dim=-1, keepdim=True)
80
+
81
+ similarity = (image_embeds @ text_embeds.T)
82
  print(similarity)