JustinLin610 commited on
Commit
4ad19d6
·
1 Parent(s): 77f28a8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +150 -0
README.md CHANGED
@@ -1,3 +1,153 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+
5
+ # Chinese-CLIP-Base
6
+
7
+ ## Introduction
8
+ This is the smallest model of the Chinese CLIP series, ResNet-50 as the image encoder and RBT3 as the text encoder. Chinese CLIP is a simple implementation of CLIP on a large-scale dataset of around 200 million Chinese image-text pairs. For more details, please refer to our technical report https://arxiv.org/abs/2211.01335 and our official github repo https://github.com/OFA-Sys/Chinese-CLIP
9
+
10
+ ## Use with the official API
11
+ We provide a simple code snippet to show how to use the API for Chinese-CLIP. For starters, please install cn_clip:
12
+ ```bash
13
+ # to install the latest stable release
14
+ pip install cn_clip
15
+
16
+ # or install from source code
17
+ cd Chinese-CLIP
18
+ pip install -e .
19
+ ```
20
+ After installation, use Chinese CLIP as shown below:
21
+ ```python
22
+ import torch
23
+ from PIL import Image
24
+
25
+ import cn_clip.clip as clip
26
+ from cn_clip.clip import load_from_name, available_models
27
+ print("Available models:", available_models())
28
+ # Available models: ['ViT-B-16', 'ViT-L-14', 'ViT-L-14-336', 'ViT-H-14', 'RN50']
29
+
30
+ device = "cuda" if torch.cuda.is_available() else "cpu"
31
+ model, preprocess = load_from_name("ViT-B-16", device=device, download_root='./')
32
+ model.eval()
33
+ image = preprocess(Image.open("examples/pokemon.jpeg")).unsqueeze(0).to(device)
34
+ text = clip.tokenize(["杰尼龟", "妙蛙种子", "小火龙", "皮卡丘"]).to(device)
35
+
36
+ with torch.no_grad():
37
+ image_features = model.encode_image(image)
38
+ text_features = model.encode_text(text)
39
+ # Normalize the features. Please use the normalized features for downstream tasks.
40
+ image_features /= image_features.norm(dim=-1, keepdim=True)
41
+ text_features /= text_features.norm(dim=-1, keepdim=True)
42
+
43
+ logits_per_image, logits_per_text = model.get_similarity(image, text)
44
+ probs = logits_per_image.softmax(dim=-1).cpu().numpy()
45
+
46
+ print("Label probs:", probs) # [[1.268734e-03 5.436878e-02 6.795761e-04 9.436829e-01]]
47
+ ```
48
+
49
+ However, if you are not satisfied with only using the API, feel free to check our github repo https://github.com/OFA-Sys/Chinese-CLIP for more details about training and inference.
50
+ <br><br>
51
+
52
+ ## Results
53
+ **MUGE Text-to-Image Retrieval**:
54
+ <table border="1" width="100%">
55
+ <tr align="center">
56
+ <th>Setup</th><th colspan="4">Zero-shot</th><th colspan="4">Finetune</th>
57
+ </tr>
58
+ <tr align="center">
59
+ <td>Metric</td><td>R@1</td><td>R@5</td><td>R@10</td><td>MR</td><td>R@1</td><td>R@5</td><td>R@10</td><td>MR</td>
60
+ </tr>
61
+ <tr align="center">
62
+ <td width="120%">Wukong</td><td>42.7</td><td>69.0</td><td>78.0</td><td>63.2</td><td>52.7</td><td>77.9</td><td>85.6</td><td>72.1</td>
63
+ </tr>
64
+ <tr align="center">
65
+ <td width="120%">R2D2</td><td>49.5</td><td>75.7</td><td>83.2</td><td>69.5</td><td>60.1</td><td>82.9</td><td>89.4</td><td>77.5</td>
66
+ </tr>
67
+ <tr align="center">
68
+ <td width="120%">CN-CLIP</td><td>63.0</td><td>84.1</td><td>89.2</td><td>78.8</td><td>68.9</td><td>88.7</td><td>93.1</td><td>83.6</td>
69
+ </tr>
70
+ </table>
71
+ <br>
72
+
73
+ **Flickr30K-CN Retrieval**:
74
+ <table border="1" width="120%">
75
+ <tr align="center">
76
+ <th>Task</th><th colspan="6">Text-to-Image</th><th colspan="6">Image-to-Text</th>
77
+ </tr>
78
+ <tr align="center">
79
+ <th>Setup</th><th colspan="3">Zero-shot</th><th colspan="3">Finetune</th><th colspan="3">Zero-shot</th><th colspan="3">Finetune</th>
80
+ </tr>
81
+ <tr align="center">
82
+ <td>Metric</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td>
83
+ </tr>
84
+ <tr align="center">
85
+ <td width="120%">Wukong</td><td>51.7</td><td>78.9</td><td>86.3</td><td>77.4</td><td>94.5</td><td>97.0</td><td>76.1</td><td>94.8</td><td>97.5</td><td>92.7</td><td>99.1</td><td>99.6</td>
86
+ </tr>
87
+ <tr align="center">
88
+ <td width="120%">R2D2</td><td>60.9</td><td>86.8</td><td>92.7</td><td>84.4</td><td>96.7</td><td>98.4</td><td>77.6</td><td>96.7</td><td>98.9</td><td>95.6</td><td>99.8</td><td>100.0</td>
89
+ </tr>
90
+ <tr align="center">
91
+ <td width="120%">CN-CLIP</td><td>71.2</td><td>91.4</td><td>95.5</td><td>83.8</td><td>96.9</td><td>98.6</td><td>81.6</td><td>97.5</td><td>98.8</td><td>95.3</td><td>99.7</td><td>100.0</td>
92
+ </tr>
93
+ </table>
94
+ <br>
95
+
96
+ **COCO-CN Retrieval**:
97
+ <table border="1" width="100%">
98
+ <tr align="center">
99
+ <th>Task</th><th colspan="6">Text-to-Image</th><th colspan="6">Image-to-Text</th>
100
+ </tr>
101
+ <tr align="center">
102
+ <th>Setup</th><th colspan="3">Zero-shot</th><th colspan="3">Finetune</th><th colspan="3">Zero-shot</th><th colspan="3">Finetune</th>
103
+ </tr>
104
+ <tr align="center">
105
+ <td>Metric</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td><td>R@1</td><td>R@5</td><td>R@10</td>
106
+ </tr>
107
+ <tr align="center">
108
+ <td width="120%">Wukong</td><td>53.4</td><td>80.2</td><td>90.1</td><td>74.0</td><td>94.4</td><td>98.1</td><td>55.2</td><td>81.0</td><td>90.6</td><td>73.3</td><td>94.0</td><td>98.0</td>
109
+ </tr>
110
+ <tr align="center">
111
+ <td width="120%">R2D2</td><td>56.4</td><td>85.0</td><td>93.1</td><td>79.1</td><td>96.5</td><td>98.9</td><td>63.3</td><td>89.3</td><td>95.7</td><td>79.3</td><td>97.1</td><td>98.7</td>
112
+ </tr>
113
+ <tr align="center">
114
+ <td width="120%">CN-CLIP</td><td>69.2</td><td>89.9</td><td>96.1</td><td>81.5</td><td>96.9</td><td>99.1</td><td>63.0</td><td>86.6</td><td>92.9</td><td>83.5</td><td>97.3</td><td>99.2</td>
115
+ </tr>
116
+ </table>
117
+ <br>
118
+
119
+ **Zero-shot Image Classification**:
120
+ <table border="1" width="100%">
121
+ <tr align="center">
122
+ <th>Task</th><th>CIFAR10</th><th>CIFAR100</th><th>DTD</th><th>EuroSAT</th><th>FER</th><th>FGVC</th><th>KITTI</th><th>MNIST</th><th>PC</th><th>VOC</th>
123
+ </tr>
124
+ <tr align="center">
125
+ <td width="150%">GIT</td><td>88.5</td><td>61.1</td><td>42.9</td><td>43.4</td><td>41.4</td><td>6.7</td><td>22.1</td><td>68.9</td><td>50.0</td><td>80.2</td>
126
+ </tr>
127
+ <tr align="center">
128
+ <td width="150%">ALIGN</td><td>94.9</td><td>76.8</td><td>66.1</td><td>52.1</td><td>50.8</td><td>25.0</td><td>41.2</td><td>74.0</td><td>55.2</td><td>83.0</td>
129
+ </tr>
130
+ <tr align="center">
131
+ <td width="150%">CLIP</td><td>94.9</td><td>77.0</td><td>56.0</td><td>63.0</td><td>48.3</td><td>33.3</td><td>11.5</td><td>79.0</td><td>62.3</td><td>84.0</td>
132
+ </tr>
133
+ <tr align="center">
134
+ <td width="150%">Wukong</td><td>95.4</td><td>77.1</td><td>40.9</td><td>50.3</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>
135
+ </tr>
136
+ <tr align="center">
137
+ <td width="150%">CN-CLIP</td><td>96.0</td><td>79.7</td><td>51.2</td><td>52.0</td><td>55.1</td><td>26.2</td><td>49.9</td><td>79.4</td><td>63.5</td><td>84.9</td>
138
+ </tr>
139
+ </table>
140
+ <br><br>
141
+
142
+ ## Citation
143
+ If you find Chinese CLIP helpful, feel free to cite our paper. Thanks for your support!
144
+
145
+ ```
146
+ @article{chinese-clip,
147
+ title={Chinese CLIP: Contrastive Vision-Language Pretraining in Chinese},
148
+ author={Yang, An and Pan, Junshu and Lin, Junyang and Men, Rui and Zhang, Yichang and Zhou, Jingren and Zhou, Chang},
149
+ journal={arXiv preprint arXiv:2211.01335},
150
+ year={2022}
151
+ }
152
+ ```
153
+ <br>