nlpcver commited on
Commit
f1a3258
1 Parent(s): 99d7060

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +393 -0
README.md CHANGED
@@ -1,3 +1,396 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+ # ZH-CLIP: A Chinese CLIP Model
5
+ [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/thu-ml/zhclip)
6
+
7
+ ## Models
8
+ You can download **ZH-CLIP** model from [🤗 thu-ml/zh-clip-vit-roberta-large-patch14](https://huggingface.co/thu-ml/zh-clip-vit-roberta-large-patch14). The model structure is shown below:
9
+ * Vision encoder network structure is the same as [openai/clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14), and initialize with [laion/CLIP-ViT-L-14-laion2B-s32B-b82K](https://huggingface.co/laion/CLIP-ViT-L-14-laion2B-s32B-b82K).
10
+ * Text encoder network struceure is the same as [hfl/chinese-roberta-wwm-ext-large](https://huggingface.co/hfl/chinese-roberta-wwm-ext-large) and initialized.
11
+ ## Results
12
+
13
+ #### COCO-CN Retrieval (Official Test Set):
14
+ <table>
15
+ <thead>
16
+ <tr>
17
+ <th rowspan="2">Model</th>
18
+ <th colspan="4">Text-to-Image</th>
19
+ <th colspan="4">Image-to-Text</th>
20
+ </tr>
21
+ <tr>
22
+ <th>R@1</th>
23
+ <th>R@5</th>
24
+ <th>R@10</th>
25
+ <th>Mean</th>
26
+ <th>R@1</th>
27
+ <th>R@5</th>
28
+ <th>R@10</th>
29
+ <th>Mean</th>
30
+ </tr>
31
+ </thead>
32
+ <tbody>
33
+ <tr>
34
+ <td>Clip-Chinese</td>
35
+ <td>22.60</td>
36
+ <td>50.04</td>
37
+ <td>65.24</td>
38
+ <td>45.96</td>
39
+ <td>22.8</td>
40
+ <td>49.8</td>
41
+ <td>64.1</td>
42
+ <td>45.57</td>
43
+ </tr>
44
+ <tr>
45
+ <td>mclip</td>
46
+ <td>56.51</td>
47
+ <td>83.57</td>
48
+ <td>90.79</td>
49
+ <td>76.95</td>
50
+ <td>59.9</td>
51
+ <td>87.3</td>
52
+ <td>94.1</td>
53
+ <td>80.43</td>
54
+ </tr>
55
+ <tr>
56
+ <td>Taiyi-CLIP</td>
57
+ <td>52.52</td>
58
+ <td>81.10</td>
59
+ <td>89.93</td>
60
+ <td>74.52</td>
61
+ <td>45.80</td>
62
+ <td>75.80</td>
63
+ <td>88.10</td>
64
+ <td>69.90</td>
65
+ </tr>
66
+ <tr>
67
+ <td>CN-CLIP</td>
68
+ <td>64.10</td>
69
+ <td>88.79</td>
70
+ <td>94.40</td>
71
+ <td>82.43</td>
72
+ <td>61.00</td>
73
+ <td>84.40</td>
74
+ <td>93.10</td>
75
+ <td>79.5</td>
76
+ </tr>
77
+ <tr>
78
+ <td>altclip-xlmr-l</td>
79
+ <td>62.87</td>
80
+ <td>87.18</td>
81
+ <td>94.01</td>
82
+ <td>81.35</td>
83
+ <td>63.3</td>
84
+ <td>88.3</td>
85
+ <td>95.3</td>
86
+ <td>82.3</td>
87
+ </tr>
88
+ <tr>
89
+ <td>ZH-CLIP</td>
90
+ <td><strong>68.00</strong></td>
91
+ <td><strong>89.46</strong></td>
92
+ <td><strong>95.44</strong></td>
93
+ <td><strong>84.30</strong></td>
94
+ <td><strong>68.50</strong></td>
95
+ <td><strong>90.10</strong></td>
96
+ <td><strong>96.50</strong></td>
97
+ <td><strong>85.03</strong></td>
98
+ </tr>
99
+ </tbody>
100
+ </table>
101
+
102
+ #### Flickr30K-CN Retrieval (Official Test Set):
103
+ <table>
104
+ <thead>
105
+ <tr>
106
+ <th rowspan="2">Model</th>
107
+ <th colspan="4">Text-to-Image</th>
108
+ <th colspan="4">Image-to-Text</th>
109
+ </tr>
110
+ <tr>
111
+ <th>R@1</th>
112
+ <th>R@5</th>
113
+ <th>R@10</th>
114
+ <th>Mean</th>
115
+ <th>R@1</th>
116
+ <th>R@5</th>
117
+ <th>R@10</th>
118
+ <th>Mean</th>
119
+ </tr>
120
+ </thead>
121
+ <tbody>
122
+ <tr>
123
+ <td>Clip-Chinese</td>
124
+ <td>17.76</td>
125
+ <td>40.34</td>
126
+ <td>51.88</td>
127
+ <td>36.66</td>
128
+ <td>30.4</td>
129
+ <td>55.30</td>
130
+ <td>67.10</td>
131
+ <td>50.93</td>
132
+ </tr>
133
+ <tr>
134
+ <td>mclip</td>
135
+ <td>62.3</td>
136
+ <td>86.42</td>
137
+ <td>92.58</td>
138
+ <td>80.43</td>
139
+ <td>84.4</td>
140
+ <td>97.3</td>
141
+ <td>98.9</td>
142
+ <td>93.53</td>
143
+ </tr>
144
+ <tr>
145
+ <td>Taiyi-CLIP</td>
146
+ <td>53.5</td>
147
+ <td>80.5</td>
148
+ <td>87.24</td>
149
+ <td>73.75</td>
150
+ <td>65.4</td>
151
+ <td>90.6</td>
152
+ <td>95.7</td>
153
+ <td>83.9</td>
154
+ </tr>
155
+ <tr>
156
+ <td>CN-CLIP</td>
157
+ <td>67.98</td>
158
+ <td>89.54</td>
159
+ <td>94.46</td>
160
+ <td>83.99</td>
161
+ <td>81.2</td>
162
+ <td>96.6</td>
163
+ <td>98.2</td>
164
+ <td>92.0</td>
165
+ </tr>
166
+ <tr>
167
+ <td>altclip-xlmr-l</td>
168
+ <td>69.16</td>
169
+ <td>89.94</td>
170
+ <td><strong>94.5</strong></td>
171
+ <td>84.53</td>
172
+ <td>85.1</td>
173
+ <td><strong>97.7</strong></td>
174
+ <td><strong>99.2</strong></td>
175
+ <td>94.0</td>
176
+ </tr>
177
+ <tr>
178
+ <td>ZH-CLIP</td>
179
+ <td><strong>69.64</strong></td>
180
+ <td><strong>90.14</strong></td>
181
+ <td>94.3</td>
182
+ <td><strong>84.69</strong></td>
183
+ <td><strong>86.6</strong></td>
184
+ <td>97.6</td>
185
+ <td>98.8</td>
186
+ <td><strong>94.33</strong></td>
187
+ </tr>
188
+ </tbody>
189
+ </table>
190
+
191
+
192
+ #### Muge Text-to-Image Retrieval (Official Validation Set):
193
+ <table>
194
+ <thead>
195
+ <tr>
196
+ <th rowspan="2">Model</th>
197
+ <th colspan="4">Text-to-Image</th>
198
+ </tr>
199
+ <tr>
200
+ <th>R@1</th>
201
+ <th>R@5</th>
202
+ <th>R@10</th>
203
+ <th>Mean</th>
204
+ </tr>
205
+ </thead>
206
+ <tbody>
207
+ <tr>
208
+ <td>Clip-Chinese</td>
209
+ <td>15.06</td>
210
+ <td>34.96</td>
211
+ <td>46.21</td>
212
+ <td>32.08</td>
213
+ </tr>
214
+ <tr>
215
+ <td>mclip</td>
216
+ <td>22.34</td>
217
+ <td>41.15</td>
218
+ <td>50.26</td>
219
+ <td>37.92</td>
220
+ </tr>
221
+ <tr>
222
+ <td>Taiyi-CLIP</td>
223
+ <td>42.09</td>
224
+ <td>67.75</td>
225
+ <td>77.21</td>
226
+ <td>62.35</td>
227
+ </tr>
228
+ <tr>
229
+ <td>cn-clip</td>
230
+ <td>56.25</td>
231
+ <td><strong>79.87</strong></td>
232
+ <td>86.50</td>
233
+ <td>74.21</td>
234
+ </tr>
235
+ <tr>
236
+ <td>altclip-xlmr-l</td>
237
+ <td>29.69</td>
238
+ <td>49.92</td>
239
+ <td>58.87</td>
240
+ <td>46.16</td>
241
+ </tr>
242
+ <tr>
243
+ <td>ZH-CLIP</td>
244
+ <td><strong>56.75</strong></td>
245
+ <td>79.75</td>
246
+ <td><strong>86.66</strong></td>
247
+ <td><strong>74.38</strong></td>
248
+ </tr>
249
+ </tbody>
250
+ </table>
251
+
252
+ #### Zero-shot Image Classification:
253
+ <table>
254
+ <thead>
255
+ <tr>
256
+ <th rowspan="2">Model</th>
257
+ <th colspan="11">Zero-shot Classification (ACC1)</th>
258
+ </tr>
259
+ <tr>
260
+ <th>CIFAR10</th>
261
+ <th>CIFAR100</th>
262
+ <th>DTD</th>
263
+ <th>EuroSAT</th>
264
+ <th>FER</th>
265
+ <th>FGVC</th>
266
+ <th>KITTI</th>
267
+ <th>MNIST</th>
268
+ <th>PC</th>
269
+ <th>VOC</th>
270
+ <th>ImageNet</th>
271
+ </tr>
272
+ </thead>
273
+ <tbody>
274
+ <tr>
275
+ <td>Clip-Chinese</td>
276
+ <td>86.85</td>
277
+ <td>44.21</td>
278
+ <td>18.40</td>
279
+ <td>34.86</td>
280
+ <td>14.21</td>
281
+ <td>3.87</td>
282
+ <td>32.63</td>
283
+ <td>14.37</td>
284
+ <td>52.49</td>
285
+ <td>67.73</td>
286
+ <td>22.22</td>
287
+ </tr>
288
+ <tr>
289
+ <td>mclip</td>
290
+ <td>92.88</td>
291
+ <td>65.54</td>
292
+ <td>29.57</td>
293
+ <td>46.76</td>
294
+ <td>41.18</td>
295
+ <td>7.20</td>
296
+ <td>23.21</td>
297
+ <td>52.80</td>
298
+ <td>51.64</td>
299
+ <td>77.56</td>
300
+ <td>42.99</td>
301
+ </tr>
302
+ <tr>
303
+ <td>Taiyi-CLIP</td>
304
+ <td>95.62</td>
305
+ <td>73.30</td>
306
+ <td>40.69</td>
307
+ <td><strong>61.62</strong></td>
308
+ <td>36.22</td>
309
+ <td>13.98</td>
310
+ <td><strong>41.21</strong></td>
311
+ <td><strong>73.91</strong></td>
312
+ <td>50.02</td>
313
+ <td>75.28</td>
314
+ <td>49.82</td>
315
+ </tr>
316
+ <tr>
317
+ <td>CN-CLIP</td>
318
+ <td>94.75</td>
319
+ <td>75.04</td>
320
+ <td>44.73</td>
321
+ <td>52.34</td>
322
+ <td>48.57</td>
323
+ <td>20.55</td>
324
+ <td>20.11</td>
325
+ <td>61.99</td>
326
+ <td><strong>62.59</strong></td>
327
+ <td><strong>79.12</strong></td>
328
+ <td>53.40</td>
329
+ </tr>
330
+ <tr>
331
+ <td>Altclip-xlmr-l</td>
332
+ <td>95.49</td>
333
+ <td>77.29</td>
334
+ <td>42.07</td>
335
+ <td>56.96</td>
336
+ <td><strong>51.52</strong></td>
337
+ <td><strong>26.85</strong></td>
338
+ <td>24.89</td>
339
+ <td>65.68</td>
340
+ <td>50.02</td>
341
+ <td>77.99</td>
342
+ <td><strong>59.21</strong></td>
343
+ </tr>
344
+ <tr>
345
+ <td>ZH-CLIP</td>
346
+ <td><strong>97.08</strong></td>
347
+ <td><strong>80.73</strong></td>
348
+ <td><strong>47.66</strong></td>
349
+ <td>51.58</td>
350
+ <td>48.48</td>
351
+ <td>20.73</td>
352
+ <td>20.11</td>
353
+ <td>61.94</td>
354
+ <td>62.31</td>
355
+ <td>78.07</td>
356
+ <td>56.87</td>
357
+ </tr>
358
+ </tbody>
359
+ </table>
360
+
361
+ ## Getting Started
362
+ ### Dependency
363
+ * python >= 3.9
364
+ * pip install -r requirements.txt
365
+ ### Inference
366
+ You can clone code from https://github.com/thu-ml/zh-clip
367
+ ```python
368
+ from PIL import Image
369
+ import requests
370
+ from models.zhclip import ZhCLIPProcessor, ZhCLIPModel # Code in https://github.com/thu-ml/zh-clip
371
+
372
+ version = 'thu-ml/zh-clip-vit-roberta-large-patch14'
373
+ model = ZhCLIPModel.from_pretrained(version)
374
+ processor = ZhCLIPProcessor.from_pretrained(version)
375
+
376
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
377
+ image = Image.open(requests.get(url, stream=True).raw)
378
+ inputs = processor(text=["一只猫", "一只狗"], images=image, return_tensors="pt", padding=True)
379
+
380
+ outputs = model(**inputs)
381
+ image_features = outputs.image_features
382
+ text_features = outputs.text_features
383
+ text_probs = (image_features @ text_features.T).softmax(dim=-1)
384
+ ```
385
+ ### Other Chinese CLIP Models
386
+ In addition, to compare the effectiveness of different methods, the inference methods of other Chinese CLIP models have been integrated. For the convenience of use, the inference code has also been made public, and please contact us if there is any infringement. The code only implements models at the same level as clip-vit-large-patch14, but it may be adapted for the use of more different versions of models in the future.
387
+ | # | model | alias |
388
+ | :----: | :---------- | :---------- |
389
+ | 0 | [ZH-CLIP](https://github.com/thu-ml/zh-clip) | zhclip |
390
+ | 1 | [AltCLIP](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltCLIP) | altclip |
391
+ | 2 | [Chinese-CLIP](https://github.com/OFA-Sys/Chinese-CLIP) | cnclip |
392
+ | 3 | [TaiyiCLIP](https://github.com/IDEA-CCNL/Fengshenbang-LM) | taiyiclip |
393
+ | 4 | [Multilingual-CLIP](https://github.com/FreddeFrallan/Multilingual-CLIP) | mclip |
394
+ | 5 | [CLIP-Chinese](https://github.com/yangjianxin1/CLIP-Chinese) | clip-chinese |
395
+
396
+ Usage in [inference.py](https://github.com/thu-ml/zh-clip/blob/main/inference.py)