Zero-Shot Image Classification
Transformers
Safetensors
tipsv2
feature-extraction
vision
image-text
contrastive-learning
zero-shot
custom_code
Instructions to use google/tipsv2-l14 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/tipsv2-l14 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="google/tipsv2-l14", trust_remote_code=True) pipe( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png", candidate_labels=["animals", "humans", "landscape"], )# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("google/tipsv2-l14", trust_remote_code=True) model = AutoModel.from_pretrained("google/tipsv2-l14", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files11 unmodified lines1213141516171819202122232425262728293031323323 unmodified lines57585960616263646566676869707172734 unmodified lines787980818283848586878889909192939495969798993 unmodified lines10310410510610710810911011111211311411511611711811912011 unmodified lines# TIPSv2 — L/14TIPSv2 (Text-Image Pre-training with Spatial awareness) is a family ofcontrastive vision-language models that produce spatially rich image featuresaligned with text embeddings. This is the **Large** variant with a ViT-L/14vision encoder and a matching text encoder.| Variant | Vision params | Text params | Embed dim ||---------|--------------|-------------|-----------|| B/14 | 86M | 110M | 768 || **L/14 (this)** | **303M** | **184M** | **1024** || SO400m/14 | 412M | 448M | 1152 || g/14 | 1.1B | 389M | 1536 |## Usage### Install dependencies```bashpip install transformers torch torchvision sentencepiece```23 unmodified linesimage = transform(Image.open("photo.jpg")).unsqueeze(0)out = model.encode_image(image)out.cls_token # (B, 1, 1024) — global CLS featureout.patch_tokens # (B, 1024, 1024) — spatial features (32x32 grid)```### Encode textPass strings directly — tokenization is handled internally.```pythontext_emb = model.encode_text(["a photo of a cat", "a photo of a dog"])# text_emb: (2, 1024)```### Zero-shot classification4 unmodified linescls = F.normalize(out.cls_token[:, 0, :], dim=-1)text_emb = F.normalize(model.encode_text(["cat", "dog", "car"]), dim=-1)similarity = cls @ text_emb.T # (B, num_classes)prediction = similarity.argmax(dim=-1)```### Zero-shot segmentationUse spatial patch tokens for dense prediction tasks.```pythonimport numpy as npfrom sklearn.decomposition import PCA# Spatial featuresspatial = out.patch_tokens.reshape(1, 32, 32, 1024) # (B, H, W, D)# PCA visualizationfeat = spatial[0].detach().numpy().reshape(-1, 1024)rgb = PCA(n_components=3).fit_transform(feat).reshape(32, 32, 3)```3 unmodified lines```pythonmodel = model.cuda()out = model.encode_image(image.cuda())text_emb = model.encode_text(["a city"]) # auto-moved to model device```## Model details- **Architecture**: ViT-L/14 vision encoder (24 layers) + Transformer text encoder (12 layers)- **Pre-training**: Contrastive image-text learning with spatial awareness- **Image preprocessing**: Resize to 448x448, convert to `[0, 1]` (no normalization)- **Text preprocessing**: SentencePiece tokenizer, lowercased, max 64 tokens- **Patch size**: 14x14 pixels- **Register tokens**: 1- **Position embeddings**: Interpolated at inference, supports any resolution## License11 unmodified lines121314151617181920212223242526272823 unmodified lines5253545556575859606162636465664 unmodified lines71727374757677787980818283848586873 unmodified lines91929394959697989910010110210310410511 unmodified lines# TIPSv2 — L/14TIPSv2 (Text-Image Pre-training with Spatial awareness) is a family of contrastive vision-language models that produce spatially rich image features aligned with text embeddings. This is the Large variant with a ViT-L/14 vision encoder and a matching text encoder.| Variant | Vision params | Text params | Embed dim ||---------|--------------|-------------|-----------|| B/14 | 86M | 110M | 768 || L/14 | 303M | 184M | 1024 || SO400m/14 | 412M | 448M | 1152 || g/14 | 1.1B | 389M | 1536 |## Usage```bashpip install transformers torch torchvision sentencepiece```23 unmodified linesimage = transform(Image.open("photo.jpg")).unsqueeze(0)out = model.encode_image(image)out.cls_token # (B, 1, 1024)out.patch_tokens # (B, 1024, 1024)```### Encode text```pythontext_emb = model.encode_text(["a photo of a cat", "a photo of a dog"])# (2, 1024)```### Zero-shot classification4 unmodified linescls = F.normalize(out.cls_token[:, 0, :], dim=-1)text_emb = F.normalize(model.encode_text(["cat", "dog", "car"]), dim=-1)similarity = cls @ text_emb.Tprediction = similarity.argmax(dim=-1)```### Zero-shot segmentation```pythonimport numpy as npfrom sklearn.decomposition import PCAspatial = out.patch_tokens.reshape(1, 32, 32, 1024)feat = spatial[0].detach().numpy().reshape(-1, 1024)rgb = PCA(n_components=3).fit_transform(feat).reshape(32, 32, 3)```3 unmodified lines```pythonmodel = model.cuda()out = model.encode_image(image.cuda())text_emb = model.encode_text(["a city"])```## Model details- **Architecture**: ViT-L/14 vision encoder (24 layers) + Transformer text encoder (12 layers)- **Image preprocessing**: resize to any resolution, convert to `[0, 1]` (no ImageNet normalization)- **Text preprocessing**: SentencePiece tokenizer, lowercased, max 64 tokens- **Patch size**: 14x14 pixels## License
README.md+9-24