Zero-Shot Image Classification
OpenCLIP
clip
visheratin commited on
Commit
6ac9aef
1 Parent(s): 08770d2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -2
README.md CHANGED
@@ -3,6 +3,60 @@ 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-base-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-600M) and an image encoder from the
14
+ [SigLIP](https://huggingface.co/timm/ViT-B-16-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-base-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
+ This model is integrated into OpenCLIP so that you can use it as any other model:
25
+
26
+ ```
27
+ !pip install -U open_clip_torch
28
+ ```
29
+
30
+ ```
31
+ from open_clip import create_model_from_pretrained, get_tokenizer
32
+ from PIL import Image
33
+ import requests
34
+ import torch
35
+
36
+ model, transform = create_model_from_pretrained("nllb-clip-base-siglip", "v1", device="cuda")
37
+
38
+ tokenizer = get_tokenizer("nllb-clip-base-siglip")
39
+
40
+ class_options = ["бабочка", "butterfly", "kat"]
41
+ class_langs = ["rus_Cyrl", "eng_Latn", "afr_Latn"]
42
+
43
+ text_inputs = []
44
+ for i in range(len(class_options)):
45
+ tokenizer.set_language(class_langs[i])
46
+ text_inputs.append(tokenizer(class_options[i]))
47
+ text_inputs = torch.stack(text_inputs).squeeze(1).to("cuda")
48
+
49
+ image_path = "https://huggingface.co/spaces/jjourney1125/swin2sr/resolve/main/samples/butterfly.jpg"
50
+ image = Image.open(requests.get(image_path, stream=True).raw)
51
+
52
+ image_inputs = transform(image).unsqueeze(0).to("cuda")
53
+
54
+ with torch.inference_mode():
55
+ logits_per_image, logits_per_text = model.get_logits(image_inputs, text_inputs)
56
+
57
+ print(logits_per_image.softmax(dim=-1))
58
+ ```
59
+
60
+ ## Acknowledgements
61
+
62
+ I thank [ML Collective](https://mlcollective.org/) for providing Google Cloud compute resources to train the OpenCLIP-compatible version of NLLB-CLIP.