Zero-Shot Image Classification
Transformers
Safetensors
tipsv2
feature-extraction
vision
image-text
contrastive-learning
zero-shot
custom_code
Instructions to use google/tipsv2-so400m14 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/tipsv2-so400m14 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="google/tipsv2-so400m14", 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-so400m14", trust_remote_code=True) model = AutoModel.from_pretrained("google/tipsv2-so400m14", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Gabriele commited on
Commit ·
6b864bd
1
Parent(s): 190b924
Remove zero-shot segmentation snippet, link to GitHub for advanced use cases
Browse files11 unmodified lines1213141516171859 unmodified lines7879808182838485868788899091929311 unmodified lines# TIPSv2 — SO400m/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 SO400m variant with 412M vision params and 448M text params.| Variant | Vision params | Text params | Embed dim | DPT Heads ||---------|--------------|-------------|-----------|-----------|59 unmodified linesprint(classes[similarity.argmax()]) # bus — predicted class```### Zero-shot segmentation```pythonclasses = ["bus", "snow", "mountain", "house", "road"]patch_feats = F.normalize(out.patch_tokens, dim=-1)text_emb = F.normalize(model.encode_text(classes), dim=-1)seg_map = (patch_feats @ text_emb.T).reshape(32, 32, len(classes)).argmax(dim=-1)print(seg_map.shape) # (32, 32) — per-patch class prediction```### Visualize spatial features```python11 unmodified lines1213141516171859 unmodified lines78798081828311 unmodified lines# TIPSv2 — SO400m/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 SO400m variant with 412M vision params and 448M text params. Try the code snippets below or check out the [GitHub repo](https://github.com/google-deepmind/tips) for more use cases and visualizations, including zero-shot segmentation.| Variant | Vision params | Text params | Embed dim | DPT Heads ||---------|--------------|-------------|-----------|-----------|59 unmodified linesprint(classes[similarity.argmax()]) # bus — predicted class```### Visualize spatial features```python
README.md+1-11