Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,92 @@ tags:
|
|
7 |
- clip
|
8 |
- genshin-impact
|
9 |
- game
|
10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
- clip
|
8 |
- genshin-impact
|
9 |
- game
|
10 |
+
---
|
11 |
+
|
12 |
+
# GenshinCLIP
|
13 |
+
A simple and small-size open-sourced CLIP model fine-tuned on Genshin Impact's image-text pairs.
|
14 |
+
|
15 |
+
Visit the [github](https://github.com/mrzjy/GenshinCLIP) for case study and data pair examples.
|
16 |
+
|
17 |
+
The model is far from being perfect, but could still offer some better text-image matching performance in some Genshin Impact scenarios.
|
18 |
+
|
19 |
+
## Intended uses & limitations
|
20 |
+
|
21 |
+
You can use the raw model for tasks like zero-shot image classification and image-text retrieval.
|
22 |
+
|
23 |
+
### How to use (With OpenCLIP)
|
24 |
+
|
25 |
+
Here is how to use this model to perform zero-shot image classification:
|
26 |
+
|
27 |
+
```python
|
28 |
+
import torch
|
29 |
+
import torch.nn.functional as F
|
30 |
+
from PIL import Image
|
31 |
+
import requests
|
32 |
+
from open_clip import create_model_from_pretrained, get_tokenizer
|
33 |
+
|
34 |
+
def preprocess_text(string):
|
35 |
+
return "Genshin Impact\n" + string
|
36 |
+
|
37 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
38 |
+
|
39 |
+
# load checkpoint from local path
|
40 |
+
# model_path = "path/to/open_clip_pytorch_model.bin"
|
41 |
+
# model_name = "ViT-SO400M-14-SigLIP-384"
|
42 |
+
# model, preprocess = create_model_from_pretrained(model_name=model_name, pretrained=model_path, device=device)
|
43 |
+
# tokenizer = get_tokenizer(model_name)
|
44 |
+
|
45 |
+
# or load from hub
|
46 |
+
model, preprocess = create_model_from_pretrained('hf-hub:mrzjy/GenshinImpact-CLIP-ViT-B-16-laion2B-s34B-b88K')
|
47 |
+
tokenizer = get_tokenizer('hf-hub:mrzjy/GenshinImpact-CLIP-ViT-B-16-laion2B-s34B-b88K')
|
48 |
+
|
49 |
+
# image
|
50 |
+
image_url = "https://static.wikia.nocookie.net/gensin-impact/images/3/33/Qingce_Village.png"
|
51 |
+
image = Image.open(requests.get(image_url, stream=True).raw)
|
52 |
+
image = preprocess(image).unsqueeze(0).to(device)
|
53 |
+
|
54 |
+
# text choices
|
55 |
+
labels = [
|
56 |
+
"This is an area of Liyue",
|
57 |
+
"This is an area of Mondstadt",
|
58 |
+
"This is an area of Sumeru",
|
59 |
+
"This is Qingce Village"
|
60 |
+
]
|
61 |
+
labels = [preprocess_text(l) for l in labels]
|
62 |
+
text = tokenizer(labels, context_length=model.context_length).to(device)
|
63 |
+
with torch.autocast(device_type=device.type):
|
64 |
+
with torch.no_grad():
|
65 |
+
image_features = model.encode_image(image)
|
66 |
+
text_features = model.encode_text(text)
|
67 |
+
image_features = F.normalize(image_features, dim=-1)
|
68 |
+
image_features = F.normalize(image_features, dim=-1)
|
69 |
+
text_features = F.normalize(text_features, dim=-1)
|
70 |
+
text_probs = torch.sigmoid(image_features @ text_features.T * model.logit_scale.exp() + model.logit_bias)
|
71 |
+
scores = [f"{s:.3f}" for i, s in enumerate(text_probs.tolist()[0])]
|
72 |
+
print(scores) # [0.016, 0.000, 0.001, 0.233]
|
73 |
+
```
|
74 |
+
|
75 |
+
## Model Card
|
76 |
+
### CLIP for GenshinImpact
|
77 |
+
|
78 |
+
[CLIP model](https://huggingface.co/laion/CLIP-ViT-B-16-laion2B-s34B-b88K) further fine-tuned on 17k Genshin Impact English text-image pairs at resolution 384x384.
|
79 |
+
|
80 |
+
### Training data description
|
81 |
+
|
82 |
+
There're currently 17,428 (train) and 918 (validation) text-image pairs used for model training.
|
83 |
+
|
84 |
+
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.
|
85 |
+
|
86 |
+
**Image Processing:**
|
87 |
+
- Size: Resize all images to 384x384 pixels to match the original model training settings.
|
88 |
+
- Format: Accept images in PNG or GIF format. For GIFs, extract a random frame to create a static image for text-image pairs.
|
89 |
+
|
90 |
+
**Text Processing:**
|
91 |
+
- Source: Text can be from the simple caption attribute of an HTML `<img>` tag or specified web content.
|
92 |
+
- Format: Prepend all texts with "Genshin Impact" along with some simple template to form natural language sentences.
|
93 |
+
|
94 |
+
**Data Distribution:**
|
95 |
+
|
96 |
+

|
97 |
+
|
98 |
+
**Validation Loss Curve**
|