Zero-Shot Image Classification
Transformers
Safetensors
tipsv2
feature-extraction
vision
image-text
contrastive-learning
zero-shot
custom_code
Instructions to use google/tipsv2-g14 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/tipsv2-g14 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="google/tipsv2-g14", 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-g14", trust_remote_code=True) model = AutoModel.from_pretrained("google/tipsv2-g14", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394---license: apache-2.0tags:- vision- image-text- contrastive-learning- zero-shot- feature-extractionlibrary_name: transformerspipeline_tag: zero-shot-image-classification---
# TIPSv2 — G/14
TIPSv2 (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 Giant variant with 1.1B vision params and 389M text params.
| 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```
### Load the model
```pythonfrom transformers import AutoModel
model = AutoModel.from_pretrained("google/tipsv2-g14", trust_remote_code=True)model.eval()```
### Encode images
Images should be tensors in `[0, 1]` range (just `ToTensor()`, no ImageNet normalization).
```pythonfrom torchvision import transformsfrom PIL import Image
transform = transforms.Compose([ transforms.Resize((448, 448)), transforms.ToTensor(),])
image = transform(Image.open("photo.jpg")).unsqueeze(0)out = model.encode_image(image)
out.cls_token # (B, 1, 1536)out.patch_tokens # (B, N, 1536)```
### Encode text
```pythontext_emb = model.encode_text(["a photo of a cat", "a photo of a dog"])# (2, 1536)```
### Zero-shot classification
```pythonimport torch.nn.functional as F
cls = 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)```
### GPU inference
```pythonmodel = model.cuda()out = model.encode_image(image.cuda())text_emb = model.encode_text(["a city"])```
## Model details
- **Architecture**: ViT vision encoder (40 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
Apache 2.0README.mdAdded+94