IMvision12 commited on
Commit
f7e7769
·
verified ·
1 Parent(s): cf862c4

fix readme.md

Browse files
Files changed (1) hide show
  1. README.md +72 -7
README.md CHANGED
@@ -1,26 +1,91 @@
1
  ---
2
  pipeline_tag: zero-shot-image-classification
3
  license: mit
 
4
  library_name: kerasformers
5
  tags:
6
  - keras
7
  - kerasformers
8
  - clip
9
- - jax
 
 
10
  - pytorch
 
11
  - tf
12
  ---
13
 
14
- # clip_vit_base_32 (Keras 3)
15
 
16
- Pure-Keras 3 weights for [kerasformers](https://github.com/IMvision12/KerasFormers), mirrored from the GitHub release. License: `mit`.
17
 
18
- ```python
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- from kerasformers.models.clip import CLIPModel, CLIPTokenizer
21
 
22
- model = CLIPModel.from_weights("clip_vit_base_32")
 
 
 
 
 
 
 
23
 
24
- tokenizer = CLIPTokenizer.from_weights("clip_vit_base_32")
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  pipeline_tag: zero-shot-image-classification
3
  license: mit
4
+ base_model: openai/clip-vit-base-patch32
5
  library_name: kerasformers
6
  tags:
7
  - keras
8
  - kerasformers
9
  - clip
10
+ - zero-shot-image-classification
11
+ - vision
12
+ - arxiv:2103.00020
13
  - pytorch
14
+ - jax
15
  - tf
16
  ---
17
 
18
+ ## ***See [our collection](https://huggingface.co/collections/kerasformers/clip-6a6a9c7bfdc6c38dcb984c24) for all versions of CLIP.***
19
 
20
+ # Run CLIP with Keras 3: JAX, PyTorch, or TensorFlow
21
 
22
+ [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-CLIP-blue)](https://imvision12.github.io/KerasFormers/clip/) [![Collection](https://img.shields.io/badge/HF-CLIP%20collection-yellow)](https://huggingface.co/collections/kerasformers/clip-6a6a9c7bfdc6c38dcb984c24)
23
+
24
+ # kerasformers/clip_vit_base_32
25
+
26
+ Paper: [Learning Transferable Visual Models From Natural Language Supervision (arXiv:2103.00020)](https://arxiv.org/abs/2103.00020) · [HF Papers](https://huggingface.co/papers/2103.00020)
27
+
28
+ CLIP (Contrastive Language-Image Pre-training) is a vision + text dual-encoder trained on (image, caption) pairs with a contrastive loss. Both encoders project to a shared embedding space for zero-shot classification, retrieval, and embeddings.
29
+
30
+ For more details on the model, please go to the upstream [model card](https://huggingface.co/openai/clip-vit-base-patch32).
31
+
32
+ Pure-**Keras 3** conversion of [`openai/clip-vit-base-patch32`](https://huggingface.co/openai/clip-vit-base-patch32) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
33
+
34
+ This is a **zero-shot image-text** checkpoint (`CLIPZeroShotClassify`): pass image(s) and text prompts at inference time.
35
 
36
+ ## Quick start
37
 
38
+ ```python
39
+ import os
40
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
41
+
42
+ from kerasformers.models.clip import (
43
+ CLIPProcessor,
44
+ CLIPZeroShotClassify,
45
+ )
46
 
47
+ processor = CLIPProcessor.from_weights("kerasformers/clip_vit_base_32")
48
+ model = CLIPZeroShotClassify.from_weights("kerasformers/clip_vit_base_32")
49
 
50
+ labels = [
51
+ "a photo of a cat",
52
+ "a photo of a dog",
53
+ "a photo of a car",
54
+ "a photo of a living room",
55
+ ]
56
+ inputs = processor(text=labels, image_paths="your_image.jpg")
57
+ output = model(
58
+ {
59
+ "images": inputs["images"],
60
+ "token_ids": inputs["input_ids"],
61
+ "padding_mask": inputs["attention_mask"],
62
+ }
63
+ )
64
+ print(output["image_logits"].shape)
65
  ```
66
+
67
+ Load any CLIP variant the same way with `from_weights("kerasformers/<variant>")`:
68
+
69
+ | Variant | Hub | Notes |
70
+ |---|---|---|
71
+ | `clip_vit_base_16` | [`kerasformers/clip_vit_base_16`](https://huggingface.co/kerasformers/clip_vit_base_16) | OpenAI |
72
+ | `clip_vit_base_32` | [`kerasformers/clip_vit_base_32`](https://huggingface.co/kerasformers/clip_vit_base_32) | OpenAI |
73
+ | `clip_vit_large_14` | [`kerasformers/clip_vit_large_14`](https://huggingface.co/kerasformers/clip_vit_large_14) | OpenAI |
74
+ | `clip_vit_large_14_336` | [`kerasformers/clip_vit_large_14_336`](https://huggingface.co/kerasformers/clip_vit_large_14_336) | OpenAI |
75
+ | `clip_vit_g_14` | [`kerasformers/clip_vit_g_14`](https://huggingface.co/kerasformers/clip_vit_g_14) | LAION |
76
+ | `clip_vit_bigg_14` | [`kerasformers/clip_vit_bigg_14`](https://huggingface.co/kerasformers/clip_vit_bigg_14) | LAION |
77
+
78
+ ## Tips
79
+
80
+ - Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
81
+ - Prefer `Processor.from_weights(...)` so image size and tokenizer match the variant.
82
+ - Map processor `input_ids` / `attention_mask` to model `token_ids` / `padding_mask`.
83
+ - OpenAI variants use `quick_gelu`; LAION g/G use `gelu`.
84
+ - See [CLIP docs](https://imvision12.github.io/KerasFormers/clip/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
85
+ - Community / upstream safetensors still work via the `hf:` prefix, e.g. `CLIPZeroShotClassify.from_weights("hf:openai/clip-vit-base-patch32")`.
86
+
87
+ ## Special Thanks
88
+
89
+ A huge thank you to the OpenAI CLIP and LAION authors for creating and releasing these models.
90
+
91
+ License: MIT.