Update README.md
Browse files
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
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 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)
|