P01son commited on
Commit
462ff42
·
1 Parent(s): 941931e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -0
README.md CHANGED
@@ -1,3 +1,24 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+
5
+
6
+ ```
7
+ from PIL import Image
8
+ import requests
9
+
10
+ from transformers import CLIPProcessor, CLIPModel
11
+
12
+ model = CLIPModel.from_pretrained("P01son/FaceCLIP-base-32")
13
+ processor = CLIPProcessor.from_pretrained("P01son/FaceCLIP-base-32")
14
+
15
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
16
+ image = Image.open(requests.get(url, stream=True).raw)
17
+
18
+ inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)
19
+
20
+ outputs = model(**inputs)
21
+ logits_per_image = outputs.logits_per_image # this is the image-text similarity score
22
+ probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
23
+
24
+ ```