Zero-Shot Image Classification
OpenCLIP
clip
visheratin commited on
Commit
b7f24e7
1 Parent(s): e5c191f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -2
README.md CHANGED
@@ -3,6 +3,64 @@ tags:
3
  - clip
4
  library_name: open_clip
5
  pipeline_tag: zero-shot-image-classification
6
- license: mit
 
 
7
  ---
8
- # Model card for nllb-clip-large-siglip
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  - clip
4
  library_name: open_clip
5
  pipeline_tag: zero-shot-image-classification
6
+ license: cc-by-nc-4.0
7
+ datasets:
8
+ - visheratin/laion-coco-nllb
9
  ---
10
+
11
+ ## Model Summary
12
+
13
+ NLLB-CLIP-SigLIP is a model that combines a text encoder from the [NLLB model](https://huggingface.co/facebook/nllb-200-distilled-1.3B) and an image encoder from the
14
+ [SigLIP](https://huggingface.co/timm/ViT-SO400M-14-SigLIP-384) model. This allows us to extend the model capabilities
15
+ to 201 languages of the Flores-200. NLLB-CLIP sets state-of-the-art on the [Crossmodal-3600](https://google.github.io/crossmodal-3600/) dataset by performing very
16
+ well on low-resource languages. You can find more details about the model in the [paper](https://arxiv.org/abs/2309.01859).
17
+
18
+ This version performs much better than the [standard](https://huggingface.co/visheratin/nllb-clip-large-oc) version. You can see the results
19
+ [here](https://github.com/mlfoundations/open_clip/blob/main/docs/openclip_multilingual_retrieval_results.csv) and
20
+ [here](https://github.com/gregor-ge/Babel-ImageNet/blob/main/evaluation_scripts/results_analysis.ipynb).
21
+
22
+ ## How to use
23
+
24
+ <a target="_blank" href="https://colab.research.google.com/drive/1TE_jln3SwTDzjFsGqbdxIJkwrUlnNs3i">
25
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
26
+ </a>
27
+
28
+ This model is integrated into OpenCLIP so that you can use it as any other model:
29
+
30
+ ```
31
+ !pip install -U open_clip_torch
32
+ ```
33
+
34
+ ```
35
+ from open_clip import create_model_from_pretrained, get_tokenizer
36
+ from PIL import Image
37
+ import requests
38
+ import torch
39
+
40
+ model, transform = create_model_from_pretrained("nllb-clip-base-siglip", "v1", device="cuda")
41
+
42
+ tokenizer = get_tokenizer("nllb-clip-base-siglip")
43
+
44
+ class_options = ["бабочка", "butterfly", "kat"]
45
+ class_langs = ["rus_Cyrl", "eng_Latn", "afr_Latn"]
46
+
47
+ text_inputs = []
48
+ for i in range(len(class_options)):
49
+ tokenizer.set_language(class_langs[i])
50
+ text_inputs.append(tokenizer(class_options[i]))
51
+ text_inputs = torch.stack(text_inputs).squeeze(1).to("cuda")
52
+
53
+ image_path = "https://huggingface.co/spaces/jjourney1125/swin2sr/resolve/main/samples/butterfly.jpg"
54
+ image = Image.open(requests.get(image_path, stream=True).raw)
55
+
56
+ image_inputs = transform(image).unsqueeze(0).to("cuda")
57
+
58
+ with torch.inference_mode():
59
+ logits_per_image, logits_per_text = model.get_logits(image_inputs, text_inputs)
60
+
61
+ print(logits_per_image.softmax(dim=-1))
62
+ ```
63
+
64
+ ## Acknowledgements
65
+
66
+ I thank [ML Collective](https://mlcollective.org/) for providing Google Cloud compute resources to train the OpenCLIP-compatible version of NLLB-CLIP.