Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,199 +1,158 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
### Direct Use
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
|
| 153 |
-
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
|
|
|
|
| 180 |
|
| 181 |
-
|
|
|
|
| 182 |
|
| 183 |
-
##
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
##
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
##
|
| 194 |
|
| 195 |
-
|
|
|
|
| 196 |
|
| 197 |
## Model Card Contact
|
| 198 |
|
| 199 |
-
[
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- clip
|
| 6 |
+
- vision-language
|
| 7 |
+
- image-text
|
| 8 |
+
- zero-shot
|
| 9 |
+
- retrieval
|
| 10 |
+
pipeline_tag: zero-shot-image-classification
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# LongCLIP: Unlocking the Long-Text Capability of CLIP
|
| 14 |
|
| 15 |
+
[](https://arxiv.org/abs/2403.15378)
|
| 16 |
+
[](https://eccv2024.ecva.net/)
|
| 17 |
+
[](https://github.com/creative-graphic-design/longclip-transformers)
|
| 18 |
|
| 19 |
+
## Model Description
|
| 20 |
|
| 21 |
+
LongCLIP is an enhanced version of OpenAI's CLIP that extends the maximum input text length from **77 to 248 tokens**, enabling better understanding of detailed, long-form text descriptions. This model maintains CLIP's zero-shot capabilities while significantly improving performance on long-caption retrieval tasks.
|
| 22 |
|
| 23 |
+
### Key Features
|
| 24 |
|
| 25 |
+
- 🔥 **Extended Context Length**: 248 tokens (3.2× longer than original CLIP)
|
| 26 |
+
- 🔥 **Strong Performance**: +20% R@5 on long-caption retrieval, +6% on standard retrieval
|
| 27 |
+
- 🔥 **Plug-and-Play**: Drop-in replacement for CLIP in existing workflows
|
| 28 |
+
- 🔥 **Two Model Sizes**: Base (LongCLIP-B) and Large (LongCLIP-L)
|
| 29 |
|
| 30 |
+
### Model Variants
|
| 31 |
|
| 32 |
+
| Model | Text Encoder | Vision Encoder | Params | Projection Dim |
|
| 33 |
+
| -------------- | --------------- | ---------------- | ------ | -------------- |
|
| 34 |
+
| **LongCLIP-B** | 12 layers, 512d | 12 layers, 768d | ~150M | 512 |
|
| 35 |
+
| **LongCLIP-L** | 12 layers, 768d | 24 layers, 1024d | ~430M | 768 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Uses
|
| 38 |
|
|
|
|
|
|
|
| 39 |
### Direct Use
|
| 40 |
|
| 41 |
+
LongCLIP can be used for:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
- **Zero-shot image classification** with detailed text descriptions
|
| 44 |
+
- **Image-text retrieval** with long, descriptive captions
|
| 45 |
+
- **Text-to-image generation** (e.g., Stable Diffusion XL integration)
|
| 46 |
+
- **Visual question answering** with complex queries
|
| 47 |
|
| 48 |
+
### Downstream Use
|
| 49 |
|
| 50 |
+
LongCLIP serves as a backbone for:
|
| 51 |
|
| 52 |
+
- Vision-language models requiring long text understanding
|
| 53 |
+
- Multimodal retrieval systems
|
| 54 |
+
- Content-based image search engines
|
| 55 |
+
- Automated image captioning evaluation
|
| 56 |
|
| 57 |
+
## How to Use
|
| 58 |
|
| 59 |
+
### Installation
|
| 60 |
|
| 61 |
+
```bash
|
| 62 |
+
pip install "transformers[torch,torch-vision]"
|
| 63 |
+
```
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
### Quick Start
|
| 66 |
|
| 67 |
+
```python
|
| 68 |
+
from transformers import AutoModel, AutoProcessor
|
| 69 |
+
from PIL import Image
|
| 70 |
+
import torch
|
| 71 |
|
| 72 |
+
# Load model and processor
|
| 73 |
+
model = AutoModel.from_pretrained(
|
| 74 |
+
"creative-graphic-design/LongCLIP-B",
|
| 75 |
+
trust_remote_code=True
|
| 76 |
+
)
|
| 77 |
+
processor = AutoProcessor.from_pretrained(
|
| 78 |
+
"creative-graphic-design/LongCLIP-B",
|
| 79 |
+
trust_remote_code=True
|
| 80 |
+
)
|
| 81 |
|
| 82 |
+
# Prepare inputs
|
| 83 |
+
image = Image.open("your_image.jpg")
|
| 84 |
+
texts = [
|
| 85 |
+
"A man is crossing the street with a red car parked nearby.",
|
| 86 |
+
"A man is driving a car in an urban scene."
|
| 87 |
+
]
|
| 88 |
|
| 89 |
+
inputs = processor(
|
| 90 |
+
text=texts,
|
| 91 |
+
images=image,
|
| 92 |
+
return_tensors="pt",
|
| 93 |
+
max_length=248,
|
| 94 |
+
padding="max_length"
|
| 95 |
+
)
|
| 96 |
|
| 97 |
+
# Get predictions
|
| 98 |
+
with torch.no_grad():
|
| 99 |
+
outputs = model(**inputs)
|
| 100 |
+
logits_per_image = outputs.logits_per_image
|
| 101 |
+
probs = logits_per_image.softmax(dim=-1)
|
| 102 |
|
| 103 |
+
print("Probabilities:", probs)
|
| 104 |
+
```
|
| 105 |
|
| 106 |
+
### Advanced Usage: Feature Extraction
|
| 107 |
|
| 108 |
+
```python
|
| 109 |
+
# Extract features separately (unnormalized)
|
| 110 |
+
text_inputs = processor(text=texts, return_tensors="pt", max_length=248, padding="max_length")
|
| 111 |
+
image_inputs = processor(images=image, return_tensors="pt")
|
| 112 |
|
| 113 |
+
with torch.no_grad():
|
| 114 |
+
text_features = model.get_text_features(**text_inputs)
|
| 115 |
+
image_features = model.get_image_features(**image_inputs)
|
| 116 |
|
| 117 |
+
# Compute similarity (like original CLIP)
|
| 118 |
+
logits = image_features @ text_features.T
|
| 119 |
+
probs = logits.softmax(dim=-1)
|
| 120 |
+
```
|
| 121 |
|
| 122 |
+
### Comparison with Original CLIP
|
| 123 |
|
| 124 |
+
```python
|
| 125 |
+
# Original CLIP: max 77 tokens
|
| 126 |
+
clip_text = "A cat"
|
| 127 |
|
| 128 |
+
# LongCLIP: up to 248 tokens
|
| 129 |
+
longclip_text = "A fluffy orange tabby cat with green eyes is sitting on a wooden table near a window, with sunlight streaming through the curtains in the background, creating a warm and cozy atmosphere in a modern living room."
|
| 130 |
|
| 131 |
+
# LongCLIP can handle both short and long texts effectively!
|
| 132 |
+
```
|
| 133 |
|
| 134 |
+
## Citation
|
| 135 |
|
| 136 |
+
If you use LongCLIP in your research, please cite:
|
| 137 |
|
| 138 |
+
```bibtex
|
| 139 |
+
@inproceedings{zhang2024longclip,
|
| 140 |
+
title={Long-CLIP: Unlocking the Long-Text Capability of CLIP},
|
| 141 |
+
author={Zhang, Beichen and Zhang, Pan and Dong, Xiaoyi and Zang, Yuhang and Wang, Jiaqi},
|
| 142 |
+
booktitle={European Conference on Computer Vision (ECCV)},
|
| 143 |
+
year={2024}
|
| 144 |
+
}
|
| 145 |
+
```
|
| 146 |
|
| 147 |
+
## License
|
| 148 |
|
| 149 |
+
This model is released under the MIT License, consistent with the original CLIP model.
|
| 150 |
|
| 151 |
+
## Acknowledgments
|
| 152 |
|
| 153 |
+
- **OpenAI CLIP**: Foundation model and architecture
|
| 154 |
+
- **Original Authors**: Beichen Zhang, Pan Zhang, Xiaoyi Dong, Yuhang Zang, Jiaqi Wang
|
| 155 |
|
| 156 |
## Model Card Contact
|
| 157 |
|
| 158 |
+
For questions and feedback, please open an issue on the [GitHub repository](https://github.com/creative-graphic-design/longclip-transformers).
|