| name | clip |
| description | Runs OpenAI CLIP for zero-shot image classification, image-text cosine matching, semantic search, and cross-modal retrieval in a shared embedding space. Use when labeling images without training, ranking images by a text query, or scoring vision-language similarity. Not for captioning (BLIP-2), conversational VLM chat (LLaVA), or pixel-level segmentation (SAM); never skip L2-normalizing embeddings before cosine scores. |
| version | 1.0.1 |
| author | Orchestra Research |
| license | MIT |
| dependencies | ["transformers","torch","pillow","ftfy","regex","tqdm"] |
| platforms | ["windows","linux","macos"] |
| 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 CLIP connects vision and language in a shared embedding space, enabling zero-shot image classification, image-text similarity, semantic image search, and cross-modal retrieval without fine-tuning. Trained on 400M image-text pairs; matches ResNet-50 zero-shot on ImageNet.
When to Use
Use CLIP when you need:
- Zero-shot image classification (no training data required)
- Image-text similarity or matching scores
- Semantic image search (text query โ ranked images)
- Content moderation (detect NSFW, violence, graphic content)
- Cross-modal retrieval (imageโtext, textโimage)
- Visual question answering (broad category level)
Use alternatives instead:
- BLIP-2 โ better image captioning
- LLaVA โ vision-language conversational chat
- Segment Anything (SAM) โ pixel-level image segmentation
Prerequisites
- Python 3.8+ installed on the host.
- PyTorch with CUDA support if a GPU is available (10โ50ร faster). CPU works but is slower.
- On Windows (PowerShell), ensure
python and pip are on PATH:
python --version
pip --version
- Install the OpenAI CLIP package and dependencies:
pip install git+https://github.com/openai/CLIP.git
pip install torch torchvision ftfy regex tqdm
- Verify import:
python -c "import clip; print('CLIP OK')"
Procedure
1. Load a model and preprocess function
import torch
import clip
from PIL import Image
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)
Available models (sorted by size):