name: clip
description: OpenAI's model connecting vision and language. Enables zero-shot image classification, image-text matching, and cross-modal retrieval. Trained on 400M image-text pairs. Use for image search, content moderation, or vision-language tasks without fine-tuning. Best for general-purpose image understanding.
version: 1.0.0
author: Orchestra Research
license: MIT
dependencies: [transformers, torch, pillow]
metadata:
hermes:
tags: [Multimodal, CLIP, Vision-Language, Zero-Shot, Image Classification, OpenAI, Image Search, Cross-Modal Retrieval, Content Moderation]
CLIP - Contrastive Language-Image Pre-Training
OpenAI's model that understands images from natural language.
When to use CLIP
Use when:
- - Zero-shot image classification (no training data needed)
- - Image-text similarity/matching
- - Semantic image search
- - Content moderation (detect NSFW, violence)
- - Visual question answering
- - Cross-modal retrieval (image→text, text→image)
- - 25,300+ GitHub stars
- - Trained on 400M image-text pairs
- - Matches ResNet-50 on ImageNet (zero-shot)
- - MIT License
- - BLIP-2: Better captioning
- - LLaVA: Vision-language chat
- - Segment Anything: Image segmentation
- - GitHub: https://github.com/openai/CLIP ⭐ 25,300+
- - Paper: https://arxiv.org/abs/2103.00020
- - Colab: https://colab.research.google.com/github/openai/clip/
- - License: MIT
Metrics:
Use alternatives instead:
Quick start
Installation
`bash
pip install git+https://github.com/openai/CLIP.git
pip install torch torchvision ftfy regex tqdm
`
Zero-shot classification
`python
import torch
import clip
from PIL import Image
Load model
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)
Load image
image = preprocess(Image.open("photo.jpg")).unsqueeze(0).to(device)
Define possible labels
text = clip.tokenize(["a dog", "a cat", "a bird", "a car"]).to(device)
Compute similarity
with torch.no_grad():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
# Cosine similarity
logits_per_image, logits_per_text = model(image, text)
probs = logits_per_image.softmax(dim=-1).cpu().numpy()
Print results
labels = ["a dog", "a cat", "a bird", "a car"]
for label, prob in zip(labels, probs[0]):
print(f"{label}: {prob:.2%}")
`
Available models
`python
Models (sorted by size)
models = [
"RN50", # ResNet-50
"RN101", # ResNet-101
"ViT-B/32", # Vision Transformer (recommended)
"ViT-B/16", # Better quality, slower
"ViT-L/14", # Best quality, slowest
]
model, preprocess = clip.load("ViT-B/32")
`
| Model | Parameters | Speed | Quality |
| ------- | ------------ | ------- | --------- |
| RN50 | 102M | Fast | Good |
| ViT-B/32 | 151M | Medium | Better |
| ViT-L/14 | 428M | Slow | Best |
| Operation | CPU | GPU (V100) | |
| ----------- | ----- | ------------ | |
| Image encoding | ~200ms | ~20ms | |
| Text encoding | ~50ms | ~5ms | |
| Similarity compute | <1ms | <1ms |
Limitations
1. Not for fine-grained tasks - Best for broad categories
2. Requires descriptive text - Vague labels perform poorly
3. Biased on web data - May have dataset biases
4. No bounding boxes - Whole image only
5. Limited spatial understanding - Position/counting weak
Resources