Commit
·
b704dfc
1
Parent(s):
58d0174
Update README.md
Browse files
README.md
CHANGED
@@ -3,139 +3,37 @@ tags:
|
|
3 |
- vision
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
The model uses a ViT-B/32 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.
|
21 |
-
|
22 |
-
The original implementation had two variants: one using a ResNet image encoder and the other using a Vision Transformer. This repository has the variant with the Vision Transformer.
|
23 |
-
|
24 |
-
|
25 |
-
### Documents
|
26 |
-
|
27 |
-
- [Blog Post](https://openai.com/blog/clip/)
|
28 |
-
- [CLIP Paper](https://arxiv.org/abs/2103.00020)
|
29 |
-
|
30 |
-
|
31 |
-
### Use with Transformers
|
32 |
-
|
33 |
-
```python3
|
34 |
-
from PIL import Image
|
35 |
-
import requests
|
36 |
-
|
37 |
-
from transformers import CLIPProcessor, CLIPModel
|
38 |
-
|
39 |
-
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
40 |
-
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
41 |
-
|
42 |
-
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
43 |
-
image = Image.open(requests.get(url, stream=True).raw)
|
44 |
-
|
45 |
-
inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)
|
46 |
-
|
47 |
-
outputs = model(**inputs)
|
48 |
-
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
|
49 |
-
probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
|
50 |
```
|
51 |
|
|
|
52 |
|
53 |
-
##
|
54 |
-
|
55 |
-
### Intended Use
|
56 |
-
|
57 |
-
The model is intended as a research output for research communities. We hope that this model will enable researchers to better understand and explore zero-shot, arbitrary image classification. We also hope it can be used for interdisciplinary studies of the potential impact of such models - the CLIP paper includes a discussion of potential downstream impacts to provide an example for this sort of analysis.
|
58 |
-
|
59 |
-
#### Primary intended uses
|
60 |
-
|
61 |
-
The primary intended users of these models are AI researchers.
|
62 |
-
|
63 |
-
We primarily imagine the model will be used by researchers to better understand robustness, generalization, and other capabilities, biases, and constraints of computer vision models.
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
Since the model has not been purposefully trained in or evaluated on any languages other than English, its use should be limited to English language use cases.
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
## Data
|
76 |
-
|
77 |
-
The model was trained on publicly available image-caption data. This was done through a combination of crawling a handful of websites and using commonly-used pre-existing image datasets such as [YFCC100M](http://projects.dfki.uni-kl.de/yfcc100m/). A large portion of the data comes from our crawling of the internet. This means that the data is more representative of people and societies most connected to the internet which tend to skew towards more developed nations, and younger, male users.
|
78 |
-
|
79 |
-
### Data Mission Statement
|
80 |
-
|
81 |
-
Our goal with building this dataset was to test out robustness and generalizability in computer vision tasks. As a result, the focus was on gathering large quantities of data from different publicly-available internet data sources. The data was gathered in a mostly non-interventionist manner. However, we only crawled websites that had policies against excessively violent and adult images and allowed us to filter out such content. We do not intend for this dataset to be used as the basis for any commercial or deployed model and will not be releasing the dataset.
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
## Performance and Limitations
|
86 |
-
|
87 |
-
### Performance
|
88 |
-
|
89 |
-
We have evaluated the performance of CLIP on a wide range of benchmarks across a variety of computer vision datasets such as OCR to texture recognition to fine-grained classification. The paper describes model performance on the following datasets:
|
90 |
-
|
91 |
-
- Food101
|
92 |
-
- CIFAR10
|
93 |
-
- CIFAR100
|
94 |
-
- Birdsnap
|
95 |
-
- SUN397
|
96 |
-
- Stanford Cars
|
97 |
-
- FGVC Aircraft
|
98 |
-
- VOC2007
|
99 |
-
- DTD
|
100 |
-
- Oxford-IIIT Pet dataset
|
101 |
-
- Caltech101
|
102 |
-
- Flowers102
|
103 |
-
- MNIST
|
104 |
-
- SVHN
|
105 |
-
- IIIT5K
|
106 |
-
- Hateful Memes
|
107 |
-
- SST-2
|
108 |
-
- UCF101
|
109 |
-
- Kinetics700
|
110 |
-
- Country211
|
111 |
-
- CLEVR Counting
|
112 |
-
- KITTI Distance
|
113 |
-
- STL-10
|
114 |
-
- RareAct
|
115 |
-
- Flickr30
|
116 |
-
- MSCOCO
|
117 |
-
- ImageNet
|
118 |
-
- ImageNet-A
|
119 |
-
- ImageNet-R
|
120 |
-
- ImageNet Sketch
|
121 |
-
- ObjectNet (ImageNet Overlap)
|
122 |
-
- Youtube-BB
|
123 |
-
- ImageNet-Vid
|
124 |
-
|
125 |
-
## Limitations
|
126 |
-
|
127 |
-
CLIP and our analysis of it have a number of limitations. CLIP currently struggles with respect to certain tasks such as fine grained classification and counting objects. CLIP also poses issues with regards to fairness and bias which we discuss in the paper and briefly in the next section. Additionally, our approach to testing CLIP also has an important limitation- in many cases we have used linear probes to evaluate the performance of CLIP and there is evidence suggesting that linear probes can underestimate model performance.
|
128 |
-
|
129 |
-
### Bias and Fairness
|
130 |
|
131 |
-
|
132 |
|
133 |
-
|
134 |
|
135 |
|
|
|
136 |
|
137 |
-
## Feedback
|
138 |
|
139 |
-
### Where to send questions or comments about the model
|
140 |
|
141 |
-
Please use [this Google Form](https://forms.gle/Uv7afRH5dvY34ZEs9)
|
|
|
3 |
- vision
|
4 |
---
|
5 |
|
6 |
+
# Fork of [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32) for a `zero-sho-image-classification` Inference endpoint.
|
7 |
|
8 |
+
This repository implements a `custom` task for `zero-shot-image-classification` for 🤗 Inference Endpoints. The code for the customized pipeline is in the [pipeline.py](https://huggingface.co/philschmid/clip-zero-shot-image-classification/blob/main/pipeline.py).
|
9 |
|
10 |
+
To use deploy this model a an Inference Endpoint you have to select `custom` as task to use the `pipeline.py` file.
|
11 |
|
12 |
+
### expected Request payload
|
13 |
|
14 |
+
```json
|
15 |
+
{
|
16 |
+
"image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
|
17 |
+
"candiates":["sea","palace","car","ship"]
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
```
|
20 |
|
21 |
+
below is an example on how to run a request using Python and `requests`.
|
22 |
|
23 |
+
## Run Request
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
1. prepare an image.
|
26 |
|
27 |
+
```bash
|
28 |
+
!wget https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
|
29 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
2. run request
|
32 |
|
33 |
+
```python
|
34 |
|
35 |
|
36 |
+
```
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|