mrzjy commited on
Commit
93363f2
·
verified ·
1 Parent(s): ae79151

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +124 -3
README.md CHANGED
@@ -1,3 +1,124 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - timm/ViT-SO400M-14-SigLIP-384
7
+ library_name: open_clip
8
+ tags:
9
+ - genshin-impact
10
+ - game
11
+ - clip
12
+ - siglip
13
+ - text-image-retrieval
14
+ ---
15
+
16
+ ---
17
+ license: apache-2.0
18
+ language:
19
+ - en
20
+ library_name: open_clip
21
+ pipeline_tag: zero-shot-image-classification
22
+ tags:
23
+ - clip
24
+ - genshin-impact
25
+ - game
26
+ - siglip
27
+ base_model:
28
+ - timm/ViT-SO400M-14-SigLIP-384
29
+ ---
30
+
31
+ # GenshinCLIP
32
+ A simple open-sourced [SigLIP model](https://huggingface.co/timm/ViT-SO400M-14-SigLIP-384) further fine-tuned on 15k Genshin Impact (Game Version 5.0) English text-image pairs at resolution 384x384.
33
+
34
+ Visit the [github](https://github.com/mrzjy/GenshinCLIP) for case study and data pair examples.
35
+
36
+ The model is **far from being perfect**, but could still offer some better text-image matching performance in some Genshin Impact scenarios.
37
+
38
+ - Deprecated Models (Trained on Genshin Impact Version 4.x)
39
+
40
+ | Model | Checkpoint Size | Val Loss |
41
+ |:-------------------------------------------------------------------------------------------:|:-----------------:|:----------:|
42
+ | [GenshinImpact-CLIP-ViT-B-16-laion2B-s34B-b88K](https://huggingface.co/mrzjy/GenshinImpact-CLIP-ViT-B-16-laion2B-s34B-b88K) | 0.59 GB | 1.152 |
43
+ | [GenshinImpact-ViT-SO400M-14-SigLIP-384](https://huggingface.co/mrzjy/GenshinImpact-ViT-SO400M-14-SigLIP-384) | 3.51 GB | 0.362 |
44
+
45
+ ## Intended uses & limitations
46
+
47
+ You can use the raw model for tasks like zero-shot image classification and image-text retrieval.
48
+
49
+ ### How to use (With OpenCLIP)
50
+
51
+ Here is how to use this model to perform zero-shot image classification:
52
+
53
+ ```python
54
+ import torch
55
+ import torch.nn.functional as F
56
+ from PIL import Image
57
+ import requests
58
+ from open_clip import create_model_from_pretrained, get_tokenizer
59
+
60
+ def preprocess_text(string):
61
+ return "Genshin Impact\n" + string
62
+
63
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
64
+
65
+ # load checkpoint from local path
66
+ # model_path = "path/to/open_clip_pytorch_model.bin"
67
+ # model_name = "ViT-SO400M-14-SigLIP-384"
68
+ # model, preprocess = create_model_from_pretrained(model_name=model_name, pretrained=model_path, device=device)
69
+ # tokenizer = get_tokenizer(model_name)
70
+
71
+ # or load from hub
72
+ model, preprocess = create_model_from_pretrained('hf-hub:mrzjy/GenshinImpact-5.0-ViT-SO400M-14-SigLIP-384')
73
+ tokenizer = get_tokenizer('hf-hub:mrzjy/GenshinImpact-5.0-ViT-SO400M-14-SigLIP-384')
74
+
75
+ # image
76
+ image_url = "https://static.wikia.nocookie.net/gensin-impact/images/3/33/Qingce_Village.png"
77
+ image = Image.open(requests.get(image_url, stream=True).raw)
78
+ image = preprocess(image).unsqueeze(0).to(device)
79
+
80
+ # text choices
81
+ labels = [
82
+ "This is an area of Liyue",
83
+ "This is an area of Mondstadt",
84
+ "This is an area of Sumeru",
85
+ "This is Qingce Village"
86
+ ]
87
+ labels = [preprocess_text(l) for l in labels]
88
+ text = tokenizer(labels, context_length=model.context_length).to(device)
89
+ with torch.autocast(device_type=device.type):
90
+ with torch.no_grad():
91
+ image_features = model.encode_image(image)
92
+ text_features = model.encode_text(text)
93
+ image_features = F.normalize(image_features, dim=-1)
94
+ image_features = F.normalize(image_features, dim=-1)
95
+ text_features = F.normalize(text_features, dim=-1)
96
+ text_probs = torch.sigmoid(image_features @ text_features.T * model.logit_scale.exp() + model.logit_bias)
97
+ scores = [f"{s:.3f}" for i, s in enumerate(text_probs.tolist()[0])]
98
+ print(scores)
99
+ ```
100
+
101
+ ## Model Card
102
+ ### SigLIP for GenshinImpact
103
+
104
+ [SigLIP model](https://huggingface.co/timm/ViT-SO400M-14-SigLIP-384) further fine-tuned on 15k Genshin Impact English text-image pairs at resolution 384x384.
105
+
106
+ (Note: A slight error occurred in counting training samples for deprecated models. The latest training data should actually include 3,500 additional samples compared to previous counts.)
107
+
108
+ ### Training data description
109
+
110
+ There're currently 14,573 (train) and 298 (validation) text-image pairs used for model training.
111
+
112
+ 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.
113
+
114
+ **Image Processing:**
115
+ - Size: Resize all images to 384x384 pixels to match the original model training settings.
116
+ - Format: Accept images in PNG or GIF format. For GIFs, extract a random frame to create a static image for text-image pairs.
117
+
118
+ **Text Processing:**
119
+ - Source: Text can be from the simple caption attribute of an HTML `<img>` tag or specified web content.
120
+ - Format: Prepend all texts with "Genshin Impact" along with some simple template to form natural language sentences.
121
+
122
+ **Data Distribution:**
123
+
124
+ ![data_distribution.png](img%2Fdata_distribution.png)