Update README.md
Browse files
README.md
CHANGED
@@ -4,4 +4,114 @@ language:
|
|
4 |
- en
|
5 |
library_name: open_clip
|
6 |
pipeline_tag: zero-shot-image-classification
|
7 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- en
|
5 |
library_name: open_clip
|
6 |
pipeline_tag: zero-shot-image-classification
|
7 |
+
---
|
8 |
+
|
9 |
+
# GenshinCLIP
|
10 |
+
A simple open-sourced SigLIP model fine-tuned on Genshin Impact's image-text pairs.
|
11 |
+
|
12 |
+
The model is far from being perfect, but could still offer some better text-image matching performance in some Genshin Impact scenarios.
|
13 |
+
|
14 |
+
|
15 |
+
## Case Study
|
16 |
+
|
17 |
+
| Case | Image | Multiple Choices | CLIPScore<br/>(After Finetune) | CLIPScore<br/>(Before Finetune) |
|
18 |
+
|------|----------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|---------------------------------------------------------------------|
|
19 |
+
| 1 | <img src="https://static.wikia.nocookie.net/gensin-impact/images/2/24/Ganyu_Card.png/revision/latest?cb=20230519012433" height="64"> | 1) This is an image of Kuki Shinobu<br/>2) This is an image of Ganyu<br/>3) This is an image of Keqing<br/>4) This is an image of Liyue | 1) 0.000<br>2) **0.438**<br>3) 0.000<br>4) 0.000 | 1) **1.207e-06**<br/>2) 4.144e-08<br/>3) 1.201e-07<br/>4) 2.212e-08 |
|
20 |
+
| 2 | <img src="https://static.wikia.nocookie.net/gensin-impact/images/3/33/Qingce_Village.png/revision/latest?cb=20220626161951" height="64"> | 1) This is an area of Liyue<br/>2) This is an area of Mondstadt<br/>3) This is an area of Sumeru<br/>4) This is Qingce Village | 1) 0.016<br>2) 0.000<br>3) 0.001<br>4) **0.233** | 1) 0.015<br/>2) 0.003<br/>3) 0.009<br/>4) **0.377** |
|
21 |
+
| 3 | <img src="https://static.wikia.nocookie.net/gensin-impact/images/0/0c/Enemy_Boreas.png/revision/latest?cb=20210426192800" height="64"> | 1) This is Andrius Wolf of the North<br/>2) This is Stormterror Dvalin<br/>3) This is Guardian of Apep's Oasis | 1) 1.000<br>2) 0.000<br>3) 0.000 | 1) **0.001**<br/>2) 0.000<br/>3) 0.000 |
|
22 |
+
| 4 | <img src="https://static.wikia.nocookie.net/gensin-impact/images/2/24/Item_Amakumo_Fruit_Wild.png/revision/latest?cb=20220601235905" height="64"> | 1) This is Amakumo Fruit<br/>2) This is Padisarahs<br/>3) This is Naku Weeds | 1) 0.000<br>2) 0.000<br>3) **0.024** | 1) 9.425e-07<br/>2) 1.207e-06<br/>3) **1.669e-05** |
|
23 |
+
|
24 |
+
Note: Case 4 is a bad case. (Correct answer is Amakumo Fruit)
|
25 |
+
|
26 |
+
|
27 |
+
## Intended uses & limitations
|
28 |
+
|
29 |
+
You can use the raw model for tasks like zero-shot image classification and image-text retrieval.
|
30 |
+
|
31 |
+
### How to use (With OpenCLIP)
|
32 |
+
|
33 |
+
Here is how to use this model to perform zero-shot image classification:
|
34 |
+
|
35 |
+
```python
|
36 |
+
import torch
|
37 |
+
import torch.nn.functional as F
|
38 |
+
from PIL import Image
|
39 |
+
import requests
|
40 |
+
from open_clip import create_model_from_pretrained, get_tokenizer
|
41 |
+
|
42 |
+
def preprocess_text(string):
|
43 |
+
return "Genshin Impact\n" + string
|
44 |
+
|
45 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
46 |
+
|
47 |
+
# load checkpoint from local path
|
48 |
+
# model_path = "path/to/open_clip_pytorch_model.bin"
|
49 |
+
# model_name = "ViT-SO400M-14-SigLIP-384"
|
50 |
+
# model, preprocess = create_model_from_pretrained(model_name=model_name, pretrained=model_path, device=device)
|
51 |
+
# tokenizer = get_tokenizer(model_name)
|
52 |
+
|
53 |
+
# or load from hub
|
54 |
+
model, preprocess = create_model_from_pretrained('hf-hub:mrzjy/GenshinImpact-ViT-SO400M-14-SigLIP-384')
|
55 |
+
tokenizer = get_tokenizer('hf-hub:mrzjy/GenshinImpact-ViT-SO400M-14-SigLIP-384')
|
56 |
+
|
57 |
+
# image
|
58 |
+
image_url = "https://static.wikia.nocookie.net/gensin-impact/images/3/33/Qingce_Village.png"
|
59 |
+
image = Image.open(requests.get(image_url, stream=True).raw)
|
60 |
+
image = preprocess(image).unsqueeze(0).to(device)
|
61 |
+
|
62 |
+
# text choices
|
63 |
+
labels = [
|
64 |
+
"This is an area of Liyue",
|
65 |
+
"This is an area of Mondstadt",
|
66 |
+
"This is an area of Sumeru",
|
67 |
+
"This is Qingce Village"
|
68 |
+
]
|
69 |
+
labels = [preprocess_text(l) for l in labels]
|
70 |
+
text = tokenizer(labels, context_length=model.context_length).to(device)
|
71 |
+
with torch.autocast(device_type=device.type):
|
72 |
+
with torch.no_grad():
|
73 |
+
image_features = model.encode_image(image)
|
74 |
+
text_features = model.encode_text(text)
|
75 |
+
image_features = F.normalize(image_features, dim=-1)
|
76 |
+
image_features = F.normalize(image_features, dim=-1)
|
77 |
+
text_features = F.normalize(text_features, dim=-1)
|
78 |
+
text_probs = torch.sigmoid(image_features @ text_features.T * model.logit_scale.exp() + model.logit_bias)
|
79 |
+
scores = [f"{s:.3f}" for i, s in enumerate(text_probs.tolist()[0])]
|
80 |
+
print(scores) # [0.016, 0.000, 0.001, 0.233]
|
81 |
+
```
|
82 |
+
|
83 |
+
## Model Card
|
84 |
+
### SigLIP for GenshinImpact
|
85 |
+
|
86 |
+
[SigLIP model](https://huggingface.co/timm/ViT-SO400M-14-SigLIP-384) further fine-tuned on 17k Genshin Impact English text-image pairs at resolution 384x384.
|
87 |
+
|
88 |
+
### Training data description
|
89 |
+
|
90 |
+
There're currently 17,428 (train) and 918 (validation) text-image pairs used for model training.
|
91 |
+
|
92 |
+
All the images and texts are crawled from [Genshin Fandom Wiki](https://genshin-impact.fandom.com/wiki) and are manually parsed to form text-image pairs.
|
93 |
+
|
94 |
+
**Image Processing:**
|
95 |
+
- Size: Resize all images to 384x384 pixels to match the original model training settings.
|
96 |
+
- Format: Accept images in PNG or GIF format. For GIFs, extract a random frame to create a static image for text-image pairs.
|
97 |
+
|
98 |
+
**Text Processing:**
|
99 |
+
- Source: Text can be from the simple caption attribute of an HTML `<img>` tag or specified web content.
|
100 |
+
- Format: Prepend all texts with "Genshin Impact" along with some simple template to form natural language sentences.
|
101 |
+
|
102 |
+
For example, here are some training image-text pairs:
|
103 |
+
|
104 |
+
| Image | Text |
|
105 |
+
|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
106 |
+
| <img src="img/9361c6fe-dabe-43b3-ae76-9731e4b73e1b.png" height="64"> | Genshin Impact<br/>This is Tainted Water-Splitting Phantasm.<br/>Tainted Hydro Phantasm Idle Waving 2 |
|
107 |
+
| <img src="img/911d0f58-dc35-4dfb-9afc-79a2d582881b.png" height="64"> | Genshin Impact<br/>This is Annihilation Specialist Mek.<br/>Although the Fontaine Research Institute of Kinetic Energy Engineering... ..., state apparatus enforcing the monopoly on violence. |
|
108 |
+
| <img src="img/bd94b015-153f-41de-b8d4-049ba29481e3.png" height="64"> | Genshin Impact<br/>Collei<br/>Expressions<br/>a Smiley expression |
|
109 |
+
| <img src="img/36a956e1-e6af-43bc-a71b-a893fe1bcf9e.png" height="64"> | Genshin Impact<br/>This is the map of viewpoint Nine Pillars of Peace in Cuijue Slope, Minlin, Liyue<br/>Nine shackles of stone were said to have been laid down deep in the valleys of Cuijue Slope to drive off evil and cleanse the world. |
|
110 |
+
|
111 |
+
**Data Distribution:**
|
112 |
+
|
113 |
+

|
114 |
+
|
115 |
+
**Validation Loss Curve**
|
116 |
+
|
117 |
+

|