Instructions to use nmndeep/CLIC-CLIPA-ViT-L-14-224-PixPr-RedCaps with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- OpenCLIP
How to use nmndeep/CLIC-CLIPA-ViT-L-14-224-PixPr-RedCaps with OpenCLIP:
import open_clip model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:nmndeep/CLIC-CLIPA-ViT-L-14-224-PixPr-RedCaps') tokenizer = open_clip.get_tokenizer('hf-hub:nmndeep/CLIC-CLIPA-ViT-L-14-224-PixPr-RedCaps') - Notebooks
- Google Colab
- Kaggle
consistent with clipa
Browse files- README.md +35 -14
- added_tokens.json +7 -0
- open_clip_config.json +3 -12
- tokenizer_config.json +2 -2
README.md
CHANGED
|
@@ -1,23 +1,26 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
datasets:
|
| 4 |
-
-
|
| 5 |
---
|
| 6 |
-
# Model
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
<!-- Provide the basic links for the model. -->
|
| 11 |
|
| 12 |
-
|
| 13 |
-
- **
|
| 14 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
## Model Usage
|
| 17 |
### With OpenCLIP
|
| 18 |
-
#### Note: We made modifications to the tokenizer implementation in open_clip/tokenizer.py.
|
| 19 |
-
#### For more details, refer to https://github.com/UCSC-VLAA/CLIPS.
|
| 20 |
-
|
| 21 |
```
|
| 22 |
import torch
|
| 23 |
import torch.nn.functional as F
|
|
@@ -25,8 +28,8 @@ from urllib.request import urlopen
|
|
| 25 |
from PIL import Image
|
| 26 |
from open_clip import create_model_from_pretrained, get_tokenizer
|
| 27 |
|
| 28 |
-
model, preprocess = create_model_from_pretrained('hf-hub:
|
| 29 |
-
tokenizer = get_tokenizer('hf-hub:
|
| 30 |
|
| 31 |
image = Image.open(urlopen(
|
| 32 |
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
|
@@ -44,4 +47,22 @@ with torch.no_grad(), torch.cuda.amp.autocast():
|
|
| 44 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
| 45 |
|
| 46 |
print("Label probs:", text_probs) # prints: [[0., 0., 0., 1.0]]
|
| 47 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
tags:
|
| 3 |
+
- clip
|
| 4 |
+
library_name: open_clip
|
| 5 |
+
pipeline_tag: zero-shot-image-classification
|
| 6 |
license: apache-2.0
|
| 7 |
datasets:
|
| 8 |
+
- mlfoundations/datacomp_1b
|
| 9 |
---
|
| 10 |
+
# Model card for ViT-L-14-CLIPA-datacomp1B
|
| 11 |
|
| 12 |
+
A CLIPA-v2 model...
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
## Model Details
|
| 15 |
+
- **Model Type:** Contrastive Image-Text, Zero-Shot Image Classification.
|
| 16 |
+
- **Original:** https://github.com/UCSC-VLAA/CLIPA
|
| 17 |
+
- **Dataset:** mlfoundations/datacomp_1b
|
| 18 |
+
- **Papers:**
|
| 19 |
+
- CLIPA-v2: Scaling CLIP Training with 81.1% Zero-shot ImageNet Accuracy within a $10,000 Budget; An Extra $4,000 Unlocks 81.8% Accuracy: https://arxiv.org/abs/2306.15658
|
| 20 |
+
- An Inverse Scaling Law for CLIP Training: https://arxiv.org/abs/2305.07017
|
| 21 |
|
| 22 |
## Model Usage
|
| 23 |
### With OpenCLIP
|
|
|
|
|
|
|
|
|
|
| 24 |
```
|
| 25 |
import torch
|
| 26 |
import torch.nn.functional as F
|
|
|
|
| 28 |
from PIL import Image
|
| 29 |
from open_clip import create_model_from_pretrained, get_tokenizer
|
| 30 |
|
| 31 |
+
model, preprocess = create_model_from_pretrained('hf-hub:ViT-L-14-CLIPA')
|
| 32 |
+
tokenizer = get_tokenizer('hf-hub:ViT-L-14-CLIPA')
|
| 33 |
|
| 34 |
image = Image.open(urlopen(
|
| 35 |
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
|
|
|
| 47 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
| 48 |
|
| 49 |
print("Label probs:", text_probs) # prints: [[0., 0., 0., 1.0]]
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## Citation
|
| 53 |
+
```bibtex
|
| 54 |
+
@article{li2023clipav2,
|
| 55 |
+
title={CLIPA-v2: Scaling CLIP Training with 81.1% Zero-shot ImageNet Accuracy within a $10,000 Budget; An Extra $4,000 Unlocks 81.8% Accuracy},
|
| 56 |
+
author={Xianhang Li and Zeyu Wang and Cihang Xie},
|
| 57 |
+
journal={arXiv preprint arXiv:2306.15658},
|
| 58 |
+
year={2023},
|
| 59 |
+
}
|
| 60 |
+
```
|
| 61 |
+
```bibtex
|
| 62 |
+
@inproceedings{li2023clipa,
|
| 63 |
+
title={An Inverse Scaling Law for CLIP Training},
|
| 64 |
+
author={Xianhang Li and Zeyu Wang and Cihang Xie},
|
| 65 |
+
booktitle={NeurIPS},
|
| 66 |
+
year={2023},
|
| 67 |
+
}
|
| 68 |
+
```
|
added_tokens.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"[CLS]": 101,
|
| 3 |
+
"[MASK]": 103,
|
| 4 |
+
"[PAD]": 0,
|
| 5 |
+
"[SEP]": 102,
|
| 6 |
+
"[UNK]": 100
|
| 7 |
+
}
|
open_clip_config.json
CHANGED
|
@@ -8,13 +8,10 @@
|
|
| 8 |
"patch_size": 14,
|
| 9 |
"no_ln_pre": true,
|
| 10 |
"pool_type": "avg",
|
| 11 |
-
"final_ln_after_pool": true
|
| 12 |
-
"norm_kwargs": {
|
| 13 |
-
"eps": 1e-6
|
| 14 |
-
}
|
| 15 |
},
|
| 16 |
"text_cfg": {
|
| 17 |
-
"context_length":
|
| 18 |
"vocab_size": 32000,
|
| 19 |
"hf_tokenizer_name": "bert-base-uncased",
|
| 20 |
"tokenizer_kwargs": {
|
|
@@ -24,13 +21,7 @@
|
|
| 24 |
"heads": 12,
|
| 25 |
"layers": 12,
|
| 26 |
"pool_type": "last",
|
| 27 |
-
"no_causal_mask": true
|
| 28 |
-
"act_kwargs": {
|
| 29 |
-
"approximate": "tanh"
|
| 30 |
-
},
|
| 31 |
-
"norm_kwargs": {
|
| 32 |
-
"eps": 1e-6
|
| 33 |
-
}
|
| 34 |
}
|
| 35 |
},
|
| 36 |
"preprocess_cfg": {
|
|
|
|
| 8 |
"patch_size": 14,
|
| 9 |
"no_ln_pre": true,
|
| 10 |
"pool_type": "avg",
|
| 11 |
+
"final_ln_after_pool": true
|
|
|
|
|
|
|
|
|
|
| 12 |
},
|
| 13 |
"text_cfg": {
|
| 14 |
+
"context_length": 32,
|
| 15 |
"vocab_size": 32000,
|
| 16 |
"hf_tokenizer_name": "bert-base-uncased",
|
| 17 |
"tokenizer_kwargs": {
|
|
|
|
| 21 |
"heads": 12,
|
| 22 |
"layers": 12,
|
| 23 |
"pool_type": "last",
|
| 24 |
+
"no_causal_mask": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
},
|
| 27 |
"preprocess_cfg": {
|
tokenizer_config.json
CHANGED
|
@@ -41,10 +41,10 @@
|
|
| 41 |
"special": true
|
| 42 |
}
|
| 43 |
},
|
| 44 |
-
"
|
|
|
|
| 45 |
"cls_token": "[CLS]",
|
| 46 |
"do_lower_case": true,
|
| 47 |
-
"extra_special_tokens": {},
|
| 48 |
"mask_token": "[MASK]",
|
| 49 |
"model_max_length": 512,
|
| 50 |
"pad_token": "[PAD]",
|
|
|
|
| 41 |
"special": true
|
| 42 |
}
|
| 43 |
},
|
| 44 |
+
"additional_special_tokens": [],
|
| 45 |
+
"clean_up_tokenization_spaces": true,
|
| 46 |
"cls_token": "[CLS]",
|
| 47 |
"do_lower_case": true,
|
|
|
|
| 48 |
"mask_token": "[MASK]",
|
| 49 |
"model_max_length": 512,
|
| 50 |
"pad_token": "[PAD]",
|