Zero-Shot Image Classification
Transformers
Safetensors
siglip
vision
mrgrandsky commited on
Commit
02c35f2
·
verified ·
1 Parent(s): 75de2d5

Update README.md

Browse files

the previous provided code has some errors which are fixed now and can be replicated

Files changed (1) hide show
  1. README.md +5 -1
README.md CHANGED
@@ -26,6 +26,8 @@ Here is how to use this model to perform zero-shot image classification:
26
 
27
  ```python
28
  from transformers import pipeline
 
 
29
 
30
  # load pipeline
31
  ckpt = "google/siglip2-base-patch16-224"
@@ -33,11 +35,13 @@ image_classifier = pipeline(model=ckpt, task="zero-shot-image-classification")
33
 
34
  # load image and candidate labels
35
  url = "http://images.cocodataset.org/val2017/000000039769.jpg"
 
36
  candidate_labels = ["2 cats", "a plane", "a remote"]
37
 
38
  # run inference
39
- outputs = image_classifier(image, candidate_labels)
40
  print(outputs)
 
41
  ```
42
 
43
  You can encode an image using the Vision Tower like so:
 
26
 
27
  ```python
28
  from transformers import pipeline
29
+ from urllib.request import urlopen
30
+ from PIL import Image
31
 
32
  # load pipeline
33
  ckpt = "google/siglip2-base-patch16-224"
 
35
 
36
  # load image and candidate labels
37
  url = "http://images.cocodataset.org/val2017/000000039769.jpg"
38
+ image = Image.open(urlopen(url))
39
  candidate_labels = ["2 cats", "a plane", "a remote"]
40
 
41
  # run inference
42
+ outputs = image_classifier(image, candidate_labels=candidate_labels)
43
  print(outputs)
44
+ # [{'score': 0.17189568281173706, 'label': '2 cats'}, {'score': 0.02414962463080883, 'label': 'a remote'}, {'score': 2.1914941044087755e-06, 'label': 'a plane'}]
45
  ```
46
 
47
  You can encode an image using the Vision Tower like so: